嵌套的视图主干
Nested view backbone
我正在尝试创建一个嵌套视图。Backendview调用另一个视图Listpostview,但不起作用。我在一个嵌套视图Liastpostview中插入了一个console.log,看看它是否被调用,但从未打印出来。
以下外部视图代码:
var BackendView = Backbone.View.extend({
tagName: "p",
events: {
"touchend": "goToDetails"
},
template: Handlebars.compile(template),
initialize: function () {
this.model.bind("change", this.render, this);
this.model.bind("destroy", this.close, this);
},
render: function (eventName) {
console.log(this.model);
var list=new ListPostView({model:this.model});
list.render();
return this;
},
});
return BackendView;
});
这是上面视图调用的ListPostView的代码:
var ListPostView = Backbone.View.extend({
tagName: "ul",
id: "list",
template: Handlebars.compile(template),
initialize: function () {
console.log(this.model);
this.model.bind("reset", this.render, this);
},
render: function (eventName) {
console.log("dddd"+this.model);<---this console.log will never called!?
$(this.el).empty();
_.each(this.model.models, function (ad) {
$(this.el).append(new SinglePostView({
model: ad
}).render().el);
}, this);
return this;
}
});
return ListPostView;
});
最后是上面最后一个视图调用的视图代码:
var SinglePostView = Backbone.View.extend({
tagName: "li",
events: {
"touchend": "goToDetails"
},
template: Handlebars.compile(template),
initialize: function () {
//console.log(ad);
this.model.bind("change", this.render, this);
this.model.bind("destroy", this.close, this);
},
render: function (eventName) {
var ad = this.model.toJSON();
ad.cid = this.model.cid;
$(this.el).html(this.template(ad));
console.log(this.template(ad));
return this;
},
});
return SinglePostView;
});
在BackendView
渲染方法中调用render后,它看起来不像是在使用list
变量。
我看到调用了list.render()
,但没有在DOM中的任何位置插入list.$el
元素。我要测试的第一件事是从BackendView
中的渲染方法调用this.$el.append(list.$el)
相关文章:
- angularjs中带有ui路由器的嵌套视图
- 如何加载嵌套3个状态的UI路由器UI视图模板
- 将js对象更改为使用嵌套的可观察数组敲除js视图模型
- 滚动所有嵌套的滚动条,使HTML元素进入视图
- 状态更改期间角度UI路由器中的嵌套视图滞后
- 带有ui.router的带角度的嵌套视图
- Angularjs 中的嵌套视图,每个视图都有单独的控制器
- 挖空.js嵌套视图模型不起作用
- Angular UI Router-在不了解第二级嵌套视图的情况下更改第三级嵌套视图
- EmberJS linkTo嵌套资源正在重新呈现父视图
- 创建表时在marionete.js中嵌套视图
- Angular 1.3+ui路由器+生成器ng poly嵌入嵌套(?)视图不起作用
- 与AngularJs中的嵌套视图相关
- MarionetteJS嵌套视图
- 嵌套的主干视图未添加到DOM中
- 嵌套状态的多个视图
- Ember.js-隐藏嵌套资源中的父视图
- AngularJS将ui视图嵌套到ng repeat中
- 将创建视图嵌套在Backbone.js中的显示视图中
- 主干视图嵌套