这不是那么具体,而是关于我对Backbone架构了解的常见问题。
因此,我需要直接从列表中编辑产品属性。我为产品列表创建了产品的骨干模型和骨干集合。
在列表中,您可以选择任何模型,并且系统应向下滑动该模型的“编辑界面”。
因此,我启动了要渲染列表并显示/编辑集合中特定模型的视图:
App.Views.ProductList = Backbone.View.extend({
el: '#content',
initialize: function() {
this.render();
},
events: {
'click #show': 'show', // to show model interface in the list
'click #save': 'save' // to save model changes in the list
},
show: function(e) {
var id = $(e.currentTarget).data('id');
$('#product' + id).slideToggle();
},
save: function(e) {
var id = $(e.currentTarget).data('id');
var form = $('#product' + id + ' form');
var model = this.collection.at(id);
model.set(form.serializeJSON());
model.save({
url: '/product'
});
},
render: function() {
var template = _.template($('#productList').html());
this.$el.empty().append(
template({
products: this.collection.toJSON()
})
);
return this;
}
});
因此,伙计们,我确定在更新模型集合中的模型时,我会采用非常错误的模式。我认为馆藏能够听取馆藏模型的变化。
我选择的方式model.save()
使用集合网址而不是模型网址,并且我无法覆盖集合网址。请说明您将如何解决此问题!
最后描述的问题是我定义url而不是urlRoot的模型中的cos。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句