我正在尝试查看从服务导入的集合,在客户端使用主干,并使用python/flask作为服务。当我发出GET请求时,我得到以下数据:
{"entries": [{"Title": "my title 1", "Description": "My desc 1", "Info": "Info 1", "ids": 1}, {"Title": "my title 2", "Description": "My desc 2", "Info": "Info 2", "ids": 2}]}
但是这些条目不会显示在我的页面上,即使我使用fetch。这是我的ListView代码:
var app = app || {};
app.ContactListView = Backbone.View.extend({
el: '#contacts',
initialize: function () {
this.collection = new app.ContactList();
this.collection.fetch({reset: true});
this.render();
this.listenTo( this.collection, 'reset', this.render );
},
render: function () {
this.collection.each(function( item ){
this.renderContact( item );
}, this );
},
renderContact: function ( item ) {
var contactView = new app.ContactView({
model: item
});
this.$('#ContactTable').append( contactView.render().el );
}
});
原因可能是什么?你知道吗
原因是您的集合需要一个模型数组作为其响应,但您的服务在条目下返回数组。从documentation
为了解决这个问题,您可以简单地重写parse方法以返回模型数组。你知道吗
例如:
相关问题 更多 >
编程相关推荐