我有一个奇怪的行为:
如果我调用
this.store.find('uilabel', { locale: "en" });
它返回/uielements的结果?locale=en如我所愿
但是如果我添加另一个参数,比如
this.store.find('uilabel', { locale: "en", device: "mobile" });
我得到这个错误:
Uncaught Error: Assertion Failed: Error: No model was found for 'device'
Ember正确地启动对/uielements?locale=en&device=mobile的get请求,并得到响应
有人知道为什么会这样吗?
编辑:这是可用模型。到目前为止,它是尽可能原始的:)
Application.Uilabel = DS.Model.extend({
locale: DS.attr('string'),
key: DS.attr('string'),
value: DS.attr('string'),
device: DS.attr('string'),
});
EDIT2:对不起,我可以自己提供……这里是JSON-response:
uilabels?locale=en&device=web
{
"locale": "en",
"device": "web",
"key": "server_url_dialog_default_button",
"value": "en_test"
}
谢谢
您的问题可能是JSON响应不是Ember Data期望的格式。见http://emberjs.com/guides/models/connecting-to-an-http-server/。根据规范,您的JSON响应需要采用以下格式:
{
uilabels: [{
"locale": "en",
"device": "web",
"key": "server_url_dialog_default_button",
"value": "en_test"
}]
}
因为你正在做一个this.store.find()
并传递多个参数,Ember Data期待一个结果数组而不是一个结果。因此,它将device
解释为一个完整的模型,而不是uilabels
的属性。