我使用Ember 1.13.7和Ember Data 1.13.8,默认情况下使用JSON-API标准格式化发送到API和从API接收的有效负载.
我想使用Ember Data的内置错误处理,以便向用户显示红色"错误"表单字段.我根据JSON-API标准格式化了我的API错误响应,例如
{"errors":[
{
"title":"The included.1.attributes.street name field is required.",
"code":"API_ERR",
"status":"400",
}
]}
Run Code Online (Sandbox Code Playgroud)
当我尝试保存我的模型时,正确执行错误回调.如果我在Ember Inspector中查看,我可以看到模型的"isError"值设置为true但我看不出Ember Data应该如何知道模型中哪个字段是错误状态的字段?我从官方JSON-API页面(http://jsonapi.org/format/#errors)中看到,您可以在错误响应中包含"源"对象:
source:包含对错误源的引用的对象,可选地包括以下任何成员:
指针:请求文档中关联实体的JSON指针[RFC6901] [例如,主数据对象的"/ data",或特定属性的"/ data/attributes/title"].
parameter:一个字符串,指示导致错误的查询参数.
但这是我应该做的,以便告诉Ember Data哪些字段应该标记为处于错误状态?
如果有人能帮助阐明这一点,我将不胜感激.
谢谢.
我正在使用Ember CLI,并在此处阅读了1.12.0版本的博客条目:
http://emberjs.com/blog/2015/05/13/ember-1-12-released.html#toc_instance-initializers
和这篇文章:
http://emberjs.com/deprecations/v1.x/#toc_deprecate-access-to-instances-in-initializers
但是我相信我已经正确地遵循了说明,但我仍然收到以下弃用警告:
弃用:
lookupFactory
在登记处被召集.该initializer
API不再接收一个容器,你应该使用一个instanceInitializer
从容器中查找对象.有关 详细信息,请参阅 http://emberjs.com/guides/deprecations#toc_deprecate-access-to-instances-in-initializers.
我有一个初始化程序,它注入一个名为"ui"的服务,因此我认为它是一个应用程序初始化程序而不是实例初始化程序(尽管我已经尝试过两者).我的初始化代码位于/app/initializers/ui.js下,如下所示:
export function initialize(registry, application) {
application.inject('route', 'ui', 'service:ui');
application.inject('controller', 'ui', 'service:ui');
}
export default {
name: 'ui',
initialize: initialize
};
Run Code Online (Sandbox Code Playgroud)
任何人都可以告诉我,我做错了吗?
谢谢!
更新:看起来其他人有类似的问题:
Store.push(类型,数据)已被弃用.请提供JSON-API文档对象作为store.push的第一个也是唯一的参数
我刚刚更新为ember 1.13.2和ember-data 1.13.3,我现在收到了很多本帖子标题中提到的弃用消息.我不知道是什么导致它出现,Ember Inspector的Deprecations选项卡没有显示我的代码在问题所在的位置.
如果有人能够向我解释这个消息意味着什么以及我需要做些什么来解决它,我将不胜感激.
谢谢.
更新:
我的自定义应用程序适配器如下所示
// app/adapters/application.js
import ActiveModelAdapter from 'active-model-adapter';
export default ActiveModelAdapter.extend({
host: 'http://dev.mydomain.com',
namespace: 'api/v1',
});
Run Code Online (Sandbox Code Playgroud)
它使用ActiveModelAdapter附加组件作为不同的弃用消息,说明ActiveModelAdapter将不再与v2.0.0中的ember-data捆绑在一起.但是,我已经尝试使用ember-data适配器和add on我的代码,并获得有关Store.push的相同弃用消息.
有一些堆栈跟踪,因为有相同弃用的多个版本,但这里有一对:
DEPRECATION: store.push(type, data) has been deprecated. Please provide a JSON-API document object as the first and only argument to store.push.
at ember$data$lib$system$store$$Service.extend.push (http://localhost:4200/assets/vendor.js:81014:17)
at http://localhost:4200/assets/vendor.js:83253:17
at Array.forEach (native)
at Ember.Mixin.create._extractEmbeddedHasMany (http://localhost:4200/assets/vendor.js:83251:68)
at null.<anonymous> (http://localhost:4200/assets/vendor.js:83219:22)
at http://localhost:4200/assets/vendor.js:84254:20
at cb (http://localhost:4200/assets/vendor.js:27380:11)
at OrderedSet.forEach (http://localhost:4200/assets/vendor.js:27163:11)
at Map.forEach (http://localhost:4200/assets/vendor.js:27384:18)
DEPRECATION: store.push(type, data) has been deprecated. Please provide a …
Run Code Online (Sandbox Code Playgroud)