考虑到我是 Backbone 的新手,我已经设法构建了我的第一个 Backbone 应用程序,目前它只根据本地 json 文件列出人员及其国籍:
var Person = Backbone.Model.extend({
defaults: {
Name: '',
Country:''
}
});
var PersonCollection = Backbone.Collection.extend({
model: Person,
url: 'users.json'
});
var PersonList = Backbone.View.extend ({
el: '.inner',
initialize: function () {
var people = new PersonCollection(),
that = this;
people.fetch({
success: function (PersonCollection) {
var template = _.template($('#people-template').html(), {PersonCollection: PersonCollection.models});
that.$el.html(template);
}
})
}
});
var GeneratePersonList = new PersonList();
我希望能够编辑/更新单个用户。最好的方法是什么?有一些代码示例会很好。谢谢