下面是描述问题的jsfiddle.第一个视图将elementid作为计算属性,第二个视图具有显式元素id.第一个视图的id没有被更改,而第二个视图的id具有id. http://jsfiddle.net/LZjEx/
App = Ember.Application.create();
App.MultiView = Ember.View.extend({
templateName : 'appl',
textInput: Ember.TextField.extend({
elementId : function(){
return "disk";
}.property()
})
})
App.MultiView.create().append();
<script type="text/x-handlebars" data-template-name="appl">
{{view view.textInput}}
{{view Ember.TextField elementId="answer"}}
</script>
Run Code Online (Sandbox Code Playgroud)
经过一些挖掘和实验,我发现了以下内容:
在此线程中,在设置elementId时进行了解释:https://github.com/emberjs/ember.js/issues/1549
由于视图在init上使用Ember.View.views注册,因此需要在init运行之前定义elementId.它与"inDOM"状态无关.
这是一个小提琴确认:http://jsfiddle.net/LLSQD/
App.MultiView = Ember.View.extend({
templateName : 'appl',
textInput: Ember.TextField.extend({
init: function() {
// This view's id will not be set to 'disk'.
return this._super();
this.set('elementId', 'disk');
}
}),
textInput2: Ember.TextField.extend({
init: function() {
// This view's id will be set to 'answer'.
this.set('elementId', 'answer');
return this._super();
}
})
})
Run Code Online (Sandbox Code Playgroud)
在这个线程中解释说,在初始化之前不计算计算属性:https://github.com/emberjs/ember.js/issues/777
这已在前面讨论过.create extends prototypes,它不是用于设置计算属性值.这不会发生变化.如果需要,可以考虑使用setProperties.
总的来说,因为elementId用于原型初始化,所以在构造对象后不能更改它,因此使用计算属性来确定id是错误的.您可以做的最好的事情是在init方法中设置id,然后调用this._super();
| 归档时间: |
|
| 查看次数: |
1673 次 |
| 最近记录: |