我有以下 json 字符串,我正在尝试从每个名称/值对创建一个模型。我在每个模型中都有一个名为“name”的属性
"[{"name":"A01"},{"name":"A02"},{"name":"A03"},{"name":"A04"},{"name":"A05"},{"name":"A06"},{"name":"A07"},{"name":"A08"},{"name":"A09"},{"name":"A10"},{"name":"A11"},{"name":"A12"},{"name":"A13"},{"name":"A14"},{"name":"A15"},{"name":"A16"},{"name":"B01"},{"name":"B02"},{"name":"B03"},{"name":"B04"},{"name":"B05"},{"name":"B06"},{"name":"B07"},{"name":"B08"},{"name":"B09"},{"name":"B10"},{"name":"B11"},{"name":"B12"},{"name":"B13"},{"name":"B14"},{"name":"B15"},{"name":"B16"},{"name":"C01"},{"name":"C02"},{"name":"C03"},{"name":"C04"},{"name":"C05"},{"name":"C06"},{"name":"C07"},{"name":"C08"},{"name":"C09"},{"name":"C10"},{"name":"C11"},{"name":"C12"},{"name":"C13"},{"name":"C14"},{"name":"C15"},{"name":"C16"},{"name":"D01"},{"name":"D02"},{"name":"D03"},{"name":"D04"},{"name":"D05"},{"name":"D06"},{"name":"D07"},{"name":"D08"},{"name":"D09"},{"name":"D10"},{"name":"D11"},{"name":"D12"},{"name":"D13"},{"name":"D14"},{"name":"D15"},{"name":"D16"}]"
这是我的代码,其中 Teams 是团队的集合。我为每个角色获得了一个新模型。
var myteams = new Teams( _.map(data, function(p) { return p.name } ));
var app = app || {};
var Teams = Backbone.Collection.extend({
model: app.Team,
initialize: function (models,options) { }
});
var app = app || {};
app.Team = Backbone.Model.extend({
defaults: {
name: ''
},
initialize: function(){
console.log('This is ' +typeof(this));
}
});