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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.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 如何更新计算属性?_Ember.js - Fatal编程技术网

Ember.js 如何更新计算属性?

Ember.js 如何更新计算属性?,ember.js,Ember.js,我是新来的。 在模板中,我有 {{labeltext}} 现在,我想要 默认情况下,labeltext应该是“Hello” 如果条件A,则labeltext=Wow 如果条件B,则labeltext=谢谢 有没有办法在emberjs中的组件中写入将执行上述要求的计算属性?在您的组件中 labeltext:Ember.computed('conditionVar',function(){ var val = this.get('conditionVar'); if(Ember.isEqual(

我是新来的。 在模板中,我有 {{labeltext}}

现在,我想要 默认情况下,labeltext应该是“Hello” 如果条件A,则labeltext=Wow 如果条件B,则labeltext=谢谢 有没有办法在emberjs中的组件中写入将执行上述要求的计算属性?

在您的组件中

labeltext:Ember.computed('conditionVar',function(){
 var val = this.get('conditionVar');
 if(Ember.isEqual(val,'conditionA')){
  return 'Wow';
 }
 else if(Ember.isEqual(val,'conditionB')) {
  return 'Thanks';
 }
 return 'Hello';
})
您可能有计算属性的getter和setter

labeltext: Ember.computed('conditionVar', function () {
    get(key){
      var val = this.get('conditionVar');
      if (Ember.isEqual(val, 'conditionA')) {
        return 'Wow';
      }else if (Ember.isEqual(val, 'conditionB')) {
        return 'Thanks';
      }
        return 'Hello';
    },
    set(key, value){
      // you can set conditionVar so that it will return the same value when you request it again.
      if(value === 'Wow') {
        this.set('conditionVar', 'conditionA');
      }
      else if(value === 'Thanks') {
        this.set('conditionVar', 'conditionB');
      }
     return value;
    }
    }),
请参阅组件中的官方指南:

labeltext:Ember.computed('conditionVar',function(){
 var val = this.get('conditionVar');
 if(Ember.isEqual(val,'conditionA')){
  return 'Wow';
 }
 else if(Ember.isEqual(val,'conditionB')) {
  return 'Thanks';
 }
 return 'Hello';
})
您可能有计算属性的getter和setter

labeltext: Ember.computed('conditionVar', function () {
    get(key){
      var val = this.get('conditionVar');
      if (Ember.isEqual(val, 'conditionA')) {
        return 'Wow';
      }else if (Ember.isEqual(val, 'conditionB')) {
        return 'Thanks';
      }
        return 'Hello';
    },
    set(key, value){
      // you can set conditionVar so that it will return the same value when you request it again.
      if(value === 'Wow') {
        this.set('conditionVar', 'conditionA');
      }
      else if(value === 'Thanks') {
        this.set('conditionVar', 'conditionB');
      }
     return value;
    }
    }),
参考官方指南: