Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ember.js 如何正确使用';didInsertElement';就我而言?_Ember.js_Components - Fatal编程技术网

Ember.js 如何正确使用';didInsertElement';就我而言?

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

我有以下组件代码(省略实际内容):

在插入组件之前,我不希望测试可用,但我也将数据传递给它。如果我没有插入数据,而不是.property('data'),我会直接使用.on('didInsertElement')。如果两种方法都需要,该怎么办?

1方法 仅当已插入零部件时才返回值:

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')。我想我太天真了。谢谢