This SO question解釋瞭如何將數組存儲在Ember模型中,但是如何使用自定義對象完成該操作,該操作本身也不支持supported, according to the Guides。如何在Ember模型中表示覆雜對象?
這是我建立
obj[0] = {"timeInMinutes": ">120", "occurrences": 24 };
obj[1] = {"timeInMinutes": "90-120","occurrences": 69 };
obj[2] = {"timeInMinutes": "60-90", "occurrences": 53 };
obj[3] = {"timeInMinutes": "30-60", "occurrences": 35 };
obj[4] = {"timeInMinutes": "0-30", "occurrences": 24 };
更新對象的示例。
使用this answer中提供的信息,我能夠在我的模型上創建一個數組屬性以及其他幾個值,但是我也希望能夠創建DS.attr('object')
屬性以便像這樣使用。要創建對象類型,是否需要像鏈接到SO答案中的數組那樣使用DS.Transform.extend({
?
App.Index = DS.Model.extend({
names: DS.attr('array'),
country: DS.attr('string'),
statistics: DS.attr('object')
您鏈接到了關於Ember Data模型的指南。你在使用Ember Data嗎? – 2015-01-27 00:11:30
是的,我使用EmberData,因爲它是本地存儲適配器的依賴關係 – Leahcim 2015-01-27 00:12:42