Javascript 主干木偶项视图返回html
我想呈现木偶项目视图,并将结果html()附加到我的div中。 我的代码:Javascript 主干木偶项视图返回html,javascript,jquery,html,backbone.js,marionette,Javascript,Jquery,Html,Backbone.js,Marionette,我想呈现木偶项目视图,并将结果html()附加到我的div中。 我的代码: life:function中的警报显示车型右侧。这意味着fetch工作正常。 问题是-如何获取查看结果的html。 我还尝试了$('#container').append(newprojectItemView({model:tmp}).render().el) 问题在于我用来填充集合/模型的REST服务。它返回包含一个元素的数组,而不是直接返回普通对象。您必须对来自木偶网的render事件做出反应 ... onRende
life:function
中的警报显示车型右侧。这意味着fetch工作正常。问题是-如何获取查看结果的html。
我还尝试了
$('#container').append(newprojectItemView({model:tmp}).render().el)
问题在于我用来填充集合/模型的REST服务。它返回包含一个元素的数组,而不是直接返回普通对象。您必须对来自木偶网的
render
事件做出反应
...
onRender : function() {
$('#container').append(this.$el);
}
...
new ProjectItemView({model: tmp});
tmp.fetch();
如果您想解除耦合,请从视图处理程序内部向外部世界触发一个不同的应用程序事件。如果你还没准备好,也许值得考虑。我认为你的问题只是操作顺序。试试这个:
$('#container').append((new ProjectItemView({model: tmp})).render().el);
按照以前的方式,您在构造函数上调用.render()
。使用上面的附加括号,将对实例调用.render()
。传递要查看的元素:
new ProjectItemView({model: tmp, el:'#container'}).render();
new ProjectItemView({model: tmp, el:'#container'}).render();