这是我的客户型号:
export default DS.Model.extend({
customerId: DS.attr('string'),
customerName: DS.attr('string')
});
这是我的客户序列化程序:
import DS from 'ember-data';
export default DS.RESTSerializer.extend({
primaryKey : 'customerId' // I am defining customerId as primary key
});
这是来自服务器的 JSON响应
{
"customers": [
{
"customerId": "1",
"customerName": "name 1"
},
{
"customerId": "2",
"customerName": "name 2"
},
{
"customerId": "3",
"customerName": "name 3"
}
]
}
一切正常,但是当我试图获得customerId时,我得到了未定义。
示例代码
var x = getModelInstanceFromWhere();
x.get('id'); //=> returns : "1"
x.get('customerId'); //=> returns : undefined
x.get('customerName'); //=> returns : "name 1"
x.toJSON(); //=> return obj: {customerId:undefined,customerName:"name 1"}
x.get('data'); //=> return obj: {id:"1",customerName:"name 1"}
即使将customerId用作主键,我也希望获得customerId值。 像x.get(' customerId')这样的东西必须给我customerId而不是undefined