Ember.js模型中的保留属性名称 [英] Reserved attribute names in Ember.js models
问题描述
我有一个具有以下字段的Post模型:
I have a Post model with the following fields:
BlogApp.Post = DS.Model.extend({
author: DS.attr('string'),
title: DS.attr('string'),
preamble: DS.attr('string'),
content: DS.attr('string'),
created: DS.attr('date'),
comments: DS.hasMany('BlogApp.Comment'),
lastUpdate: DS.attr('date')
});
渲染后,结果类似于Post.content:
After rendering, instead of the Post.content, the result is like:
<BlogApp.Post:ember272:1>
其他字段呈现都可以.我想content
与某些内部属性冲突.我有几个问题:
Other fields rendering are OK. I guess content
is conflicting with some internal property. I have a few questions:
- 当REST API的名称与Ember内部有冲突时,是否有任何解决方法?
- 我还应该知道其他禁止使用的属性名称吗?
[更新]
名称冲突与控制器有关,而与模型无关.它不是确定的列表,但请注意其他常见的数据库列名称,例如:
The name clash is with the controller, not with the model. It is not a definitive list but watch out for other common database column names like:
- 模型
- 交易
- is_new
- 已删除
- 商店
- 错误
我猜Ember开发人员并不像这个可怜的pythonist那样害怕与命名空间相关的错误.
I guess Ember developers not as afraid of namespace-related bugs as this poor pythonist.
顺便说一句, Angular.js 伙计们做对了:他们总是在API属性和方法上有效地加上$
前缀防止这种错误.
BTW, Angular.js guys got it right: they always prefix API attributes and methods with $
effectively preventing this kind of bug.
推荐答案
我正在尝试回答您的两个问题:
I'm trying to answer your two questions:
1
您可以为所有键定义一个映射,这里是content
属性的示例
1
you can define a mapping for all of you Keys, here an example for the content
property
App.Adapter.map('App.Post', {
myContent: {key: 'content'}
});
2
据我所知,在ember中没有这样的explicit
保留名称列表,但是根据经验,应该避免(预防性地)像content
这样的通用名称
2
as far I know there is no such explicit
list of reserved names in ember, but as a rule of thumb very generic names like content
should be avoided (preventively)
希望有帮助
这篇关于Ember.js模型中的保留属性名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!