在Ember.js模型中保留名称 [英] Reserved atribute 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>
其他字段渲染都可以。我猜内容
与某些内部属性冲突。我有几个问题:
Other fields rendering are OK. I guess content
is conflicting with some internal property. I have a few questions:
- 当REST API的名称与Ember内部构件发生冲突时,是否有工作?
- 是否还有其他forbiden属性名称我应该知道?
[更新]
名称冲突是与控制器,而不是模型。它不是一个明确的列表,但要注意其他常见的数据库列名称,如:
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
- is_deleted
- 商店
- 错误
- model
- transaction
- is_new
- is_deleted
- store
- errors
我猜Ember开发人员不像这个可怜的pythonist那样害怕与命名空间相关的错误。
I guess Ember developers not as afraid of namespace-related bugs as this poor pythonist.
BTW, 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
你可以为所有的键定义一个映射,这里是内容
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
我知道没有这样的显式的
列表中的保留名称,但作为一个经验法则,非常通用的名称,如内容
应该避免(预防)
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屋!