2013-10-31 27 views
0

我有一個變量以下數據:Backbone.js的 - 引導數據到收集

[{"age":"65","_id":"526fb6c940301e040e000002","name":{"first":"Jane","last":"Does"},"__v":0,"modified":"2013-10-31T10:03:26.435Z"},{"age":"25","_id":"526fb6c940301e040e000001","name":{"first":"John","last":"Doe"},"__v":0,"modified":"2013-10-31T10:03:26.436Z"},{"age":"45","_id":"526fb6c940301e040e000003","name":{"first":"Alice","last":"Smith"},"__v":0,"modified":"2013-10-31T10:03:26.436Z"}] 

我試圖引導我收集與此數據。

this.collections.staff = new StaffCollection; 
this.collections.staff.reset(data , {parse: true}); 

當我console.log(this.collection.staff),以下是結果:

console.log

我究竟做錯了什麼?

感謝

回答

0

您必須初始化這樣的集合:

this.collections.staff = new StaffCollection(data); 

您可以檢查它在這個JSFiddle工作。

乾杯。

+0

我用過,但都產生相同的結果。 http://documentcloud.github.io/backbone/#FAQ-bootstrap – Joe

+0

我不知道那個鏈接,但無論如何,現在我正在檢查小提琴它也適用'var staff = new StaffCollection; staff.reset(data,{parse:true});'。你有沒有修改你的分析函數@Joe? – Puigcerber

0

或許你可以嘗試以下方法:

var json_data = JSON.parse('{{data variable in String}}'); 

this.collections.staff = new StaffCollection(json_data, {parse:true});