Javascript 主干:收藏的麻烦
我正在尝试登录,然后获取项目列表。 从登录模型中,它尝试重置项目列表。问题是当集合被重置时,集合UI并没有捕捉到它。 登录模型的登录函数 仪表板列表 仪表板列表视图 仪表板项目视图 有两个问题: 来自服务器的响应与集合中预期的不一致。当我改变它时,一些静态数据。它流过 单个仪表板视图需要返回其视图对象,以便可以将其呈现到集合中 渲染:函数{ 控制台。记录“这里发生了什么” var attributes=this.model.toJSON; 这是。$el.htmlthis.templateattributes; //这个.$el.appendTo'.container'; 归还这个; },Javascript 主干:收藏的麻烦,javascript,backbone.js,Javascript,Backbone.js,我正在尝试登录,然后获取项目列表。 从登录模型中,它尝试重置项目列表。问题是当集合被重置时,集合UI并没有捕捉到它。 登录模型的登录函数 仪表板列表 仪表板列表视图 仪表板项目视图 有两个问题: 来自服务器的响应与集合中预期的不一致。当我改变它时,一些静态数据。它流过 单个仪表板视图需要返回其视图对象,以便可以将其呈现到集合中 渲染:函数{ 控制台。记录“这里发生了什么” var attributes=this.model.toJSON; 这是。$el.htmlthis.templateattr
login: function() {
this.save(
{}, {
success: function(resp) {
var list = [];
list[0] = resp.get("0");
list[1] = resp.get("1");
dashboardList.reset(list);
}
});
}
var DashboardList = Backbone.Collection.extend({
model: DashboardModel
});
var dashboardList= new DashboardList();
var DashboardListView = Backbone.View.extend({
initialize: function() {
this.collection.on('add', this.addOne, this);
this.collection.on('reset', this.addAll, this);
},
addOne: function(item) {
var viewItem = new DashboardView({model: dashboardModel});
this.$el.append(viewItem.render().el);
},
addAll: function() {
this.collection.forEach(this.addOne, this);
},
render: function() {
this.addAll();
}
});
var DashboardView = Backbone.View.extend({
template:_.template('<div>'+
'<h3><%= campaignName %></h3>'+
'<span><%= orderedAndGoal %>, </span>'+
'<span><%= status %>, </span>'+
'<span><%= endDate %>, </span>'+
'</div>'),
initialize: function() {
this.model.on('change', this.render, this);
},
render: function() {
var attributes = this.model.toJSON();
this.$el.html(this.template(attributes));
this.$el.appendTo('.container');
}
});