Ember.js 如何正确使用';didInsertElement';就我而言?
我有以下组件代码(省略实际内容): 在插入组件之前,我不希望测试可用,但我也将数据传递给它。如果我没有插入数据,而不是.property('data'),我会直接使用.on('didInsertElement')。如果两种方法都需要,该怎么办?1方法 仅当已插入零部件时才返回值:Ember.js 如何正确使用';didInsertElement';就我而言?,ember.js,components,Ember.js,Components,我有以下组件代码(省略实际内容): 在插入组件之前,我不希望测试可用,但我也将数据传递给它。如果我没有插入数据,而不是.property('data'),我会直接使用.on('didInsertElement')。如果两种方法都需要,该怎么办?1方法 仅当已插入零部件时才返回值: App.DataTableComponent = Ember.Component.extend({ onInsert: function() { this.set('isInserted', tru
App.DataTableComponent = Ember.Component.extend({
onInsert: function() {
this.set('isInserted', true);
}.on('didInsertElement'),
test: function(){
if (this.get('isInserted')) {
// compute the test property here
var someValue = this.get('data') + 5;
return someValue;
}
}.property('data', 'isInserted')
});
App.DataTableComponent = Ember.Component.extend({
onInsert: function() {
Ember.defineProperty(this, 'test',
Ember.computed(this.testComputer).property('data')
);
}.on('didInsertElement'),
testComputer: function(){
// compute the test property here
var someValue = this.get('data') + 5;
return someValue;
}
});
第二种方法 在插入零部件后定义计算特性:
App.DataTableComponent = Ember.Component.extend({
onInsert: function() {
this.set('isInserted', true);
}.on('didInsertElement'),
test: function(){
if (this.get('isInserted')) {
// compute the test property here
var someValue = this.get('data') + 5;
return someValue;
}
}.property('data', 'isInserted')
});
App.DataTableComponent = Ember.Component.extend({
onInsert: function() {
Ember.defineProperty(this, 'test',
Ember.computed(this.testComputer).property('data')
);
}.on('didInsertElement'),
testComputer: function(){
// compute the test property here
var someValue = this.get('data') + 5;
return someValue;
}
});
啊,我试着在属性之后链接它,比如.property(…).on('didInsertElement')。我想我太天真了。谢谢