2014-04-12 45 views
0

我有一個模型,定義如下:如何在Ember中獲取模型ID?

App.Product = DS.Model.extend({ 
    name: DS.attr('string'), 
    price: DS.attr('number') 
}); 

其餘端點成功返回然而產品,儘管還返回一個名爲包含旁邊的名稱和價格的整數「ID」字段,它不會讓我檢索這個ID。

product1 = this.store.find('Product', 1); 
console.log(product1.get('name'); // successful 
console.log(product1.get('id'); // undefined 

(我嘗試添加id: DS.attr('number')但灰燼不允許這樣。)

我缺少什麼?

回答

2

findpromise-aware:你應該能夠檢查ID是這樣的:

promise = this.store.find('product', '1').then(function(product) { 
    console.log(product.get('id')); 
}); 

另外,還要確保你沒有改變你的適配器的primaryKey' property to something other than id`。