コレクションを使用して、API からのデータを一覧表示しようとしています。しかし問題は、forEach を使用すると、呼び出した関数 (addOne) が実行されないことです。
私が間違って働いていると思われるものもあります。私のコレクションは、返された JSON をそのようなモデルの下に保存する必要がありますか?
Object -> models -> 0 -> attributes -> ...
私の見解:
s.Views.Fs = Backbone.View.extend({
className: "",
template: _.template("<%= name %>"),
initialize: function() {
},
render: function() {
this.collection.forEach(this.addOne, this);
},
addOne: function(f) {
alert("a");
var fV = new s.Views.PF({model: f});
this.$el.append(fV.render().el);
}
});
私のコレクション:
s.Collections.FL = Backbone.Collection.extend({
url: "api/fs/",
model: s.Models.F,
});
私のモデル:
s.Models.F = Backbone.Model.extend( {
urlRoot: 'api/fs/',
defaults: {
...
},
...
parse: function(response) {
return response;
},
});
マイ ルート (およびアプリ):
var sApp = new (Backbone.Router.extend({
f_a: function() {
this.fL= new s.Collections.FL();
this.fLV= new s.Views.Fs({collection: this.fL});
this.fL.fetch();
this.fLV.render();
},
});