私はBackboneで新しいです。だから私はRESTサービスからデータを取得しようとしています。Backbone.js + Rest。 fetch()の後でコレクションにデータが読み込まれない
これは私の単純なコードです:JSON次
$(function() {
var Entity = Backbone.Model.extend({
url: function() {
return 'http://localhost:8080/rest/entity/'+this.id;
}
});
var EntityList = Backbone.Collection.extend({
model: Entity,
url: 'http://localhost:8080/rest/entity'
});
var entityList = new EntityList();
entityList.fetch();
});
私の残りのサービスリターン:
デバッガで[{"id":1387,
"version":3,
"entityName":"entity01",
"entityLabel":"Entity01",
"entityPluralLabel":"Entity01",
"attributes":
[{"id":1425,
"slot":"D001",
"version":0,
"attributeName":"dfield",
"attributeType":
{"id":7,
"description":"Date",
"attributeType":"date",
"databaseType":"DATE"
},
"options":[],
"order":2,
"attributeLabel":"dField",
"checked":null
},
{"id":1424,
"slot":"S001",
"version":0,
"attributeName":"txfield",
"attributeType":
{"id":1,
"description":"Textbox",
"attributeType":"textbox",
"databaseType":"STRING"
},
"options":[],
"order":1,
"attributeLabel":"txField",
"checked":null
}
]
},
{"id":1426,
"version":3,
"entityName":"entity02",
"entityLabel":"Entity02",
"entityPluralLabel":"Entity02",
"attributes":
[{"id":1464,
"slot":"D001",
"version":0,
"attributeName":"dfield",
"attributeType":
{"id":7,
"description":"Date",
"attributeType":"date",
"databaseType":"DATE"
},
"options":[],
"order":2,
"attributeLabel":"dField",
"checked":null
}
]
}
]
私はどのように私ができる、その要求はRESTサービスに送信し、応答を受け取ったとした参照entityListコレクションに受信データが設定されているかどうかを確認します。デバッガのentityList.modelsは、entityList.fetch()の後に空です。
私は正しい方法で、何かが私のコードで間違っていますか?
バックボーンのソースコードは、このコードは、モデルのリストが空であることを言うだろうさ
ものすごく単純。たぶん、実際のバックボーンソースを踏んで、何が起こっているのかを知ることができます。 – Evert