0

我正在尝试使用 gridster.add_widget 方法将预渲染模板传递到 DOM 中。

我一定不明白如何使用 UI.renderWithData 因为每次调用 UI 命令时都会在最底部收到错误消息消息。

我对文档的理解是,这些命令将返回传入模板的完整 HTML。我已经通过为每个被调用的“项目”创建一个红色框来验证 gridster 工作正常。

任何帮助将不胜感激。谢谢!

Template.projects.rendered = function(){

    gridster = $(".gridster div").gridster({
        widget_margins: [10, 10],
        widget_base_dimensions: [140, 140]
    }).data('gridster');

   var projectz = Projects.find({}, {sort: { time: -1}});
   $.each(projectz, function(index, widget){
       if (widget != undefined) {
           console.log(widget);

           // This works and adds a red box for each project in the database
           gridster.add_widget('<div style="background-color: red;">');

           // This does NOT work, I assume it is an issue with my use of UI.renderWithData
        // gridster.add_widget(UI.insert(UI.renderWithData(Template.projects, widget)), 1, 1);
       }
   });
};


//
// Error I get trying to gridster.add_widget() or console.log()
// with (UI.insert(UI.renderWithData(Template.projects, widget)));
//

Exception from Deps afterFlush function function: TypeError: Cannot read property 'nodeName' of undefined
at tbodyFixNeeded (http://localhost:3000/packages/ui.js?b523ef986d3d39671bcb40319d0df8982acacfe8:1368:13)
at Function.DomRange.insert (http://localhost:3000/packages/ui.js?b523ef986d3d39671bcb40319d0df8982acacfe8:1337:7)
at Object.UI.insert (http://localhost:3000/packages/ui.js?b523ef986d3d39671bcb40319d0df8982acacfe8:2123:15)
at null.<anonymous> (http://localhost:3000/client/controllers/projects.js?c493c07746d208ff23d7a134ed4353a706244d46:41:29)
at Function.o.extend.each (http://localhost:3000/client/compatability/jquery/jquery-2.1.0.min.js?4c694ca97ed11ffba659454ac63c35e0452a994d:2:2931)
at Object.Template.projects.rendered (http://localhost:3000/client/controllers/projects.js?c493c07746d208ff23d7a134ed4353a706244d46:37:7)
at http://localhost:3000/packages/ui.js?b523ef986d3d39671bcb40319d0df8982acacfe8:424:23
at _.extend.flush (http://localhost:3000/packages/deps.js?7afb832ce6e6c89421fa70dc066201f16f9b9105:331:13) 
4

1 回答 1

0

UI.insert 需要一个 DOM 节点作为第二个参数,请参阅文档。您在没有任何其他参数的情况下调用它。

您没有将所有 Project 元素呈现到模板中的页面是否有原因?

于 2014-05-08T12:11:38.407 回答