userProjects: function(customerid) {
this.chat();
App.core.vent.trigger('app:log', 'Controller: "userProjects" route hit.');
window.customerTransactions = new CustomerTransactionsCollection([], {id:customerid});
customerTransactions.fetch({
success: function(transactions) {
App.data.transactions = transactions;
var userProjectsView = new UserProjectsView({ collection: customerTransactions });
$('.dashboard .container').html(userProjectsView.render().$el);
}
});
window.App.router.navigate('/customer/'+customerid);
}
该集合看起来有点像
[
{"id":"czy3m4","status":"authorized"},
{"id":"3sjkn8","status":"authorized"},
]
然后当我记录App.data.transactions.get('czy3m4')
时,它是未定义的。来自客户端的cid
,但模型本身没有id
,在我的其他集合中,id就在那里。
module.exports = CustomerTransactionModel = Backbone.Model.extend({
idAttribute: 'id'
});
解决方法
作为一种解决方法,我正在做这个
userProject: function(projectid) {
console.log(projectid);
this.chat();
var thisModel;
App.data.transactions.each(function(model) {
if(model.get('id') === projectid) {
thisModel = model;
}
});
App.core.vent.trigger('app:log', 'Controller: "userProject" route hit.');
var userProjectView = new UserProjectView({ model: thisModel });
$('.dashboard .container').html(userProjectView.render().$el);
window.App.router.navigate('/customer/'+customerid+'/'+projectid);
}