情况是我有一个看起来像这些的集合视图。
ContactManager.module('Entities', function (Entities, ContactManager, Backbone,
Marionette, $, _) {
Entities.Contact = Backbone.Model.extend({
});
Entities.configureStorage(Entities.Contact);
Entities.ContactCollection = Backbone.Collection.extend({
model: Entities.Contact,
comparator: "firstName"
});
var contacts;
var initializeContacts = function () {
contacts = new Entities.ContactCollection([{
id: 1,
firstName: 'Alice',
lastName: 'Arten',
phoneNumber: '555-0184'
}, {
id: 2,
firstName: 'Bob',
lastName: 'Brigham',
phoneNumber: '555-0163'
}, {
id: 3,
firstName: 'Charlie',
lastName: 'Campbell',
phoneNumber: '555-0129'
}]);
};
var API = {
getContactEntities: function () {
if (contacts === undefined) {
initializeContacts();
}
return contacts;
}
};
ContactManager.reqres.setHandler("contact:entities", function () {
return API.getContactEntities();
});
});
目前我正在使用静态值显示联系人集合,但现在我想通过调用将返回 json 的 restful web 服务来填充它。我已经尝试了很多事情,但无法做到。