Ember.js计算属性不触发

时间:2014-03-24 20:28:02

标签: javascript ember.js handlebars.js

我有一个计算属性,当选中复选框时不会触发。我只需要检查属性值从1到0。

App.Address = Ember.Object.extend({
  shipType: 1,

  shipType: function() {
    var type = this.get('shipType');
    if (type === 1) {
      type = 0;
      return type;
    } else {
      type = 1;
      return type;
    };
  }.property('shipCommerical')
}) 

在我的模板中:

<label>{{view Ember.Checkbox checkedBinding='shipCommerical'}} Check Me </label>

我有其他计算属性位于相同的位置和相同的方式。唯一的区别是它们是文本字段而不是复选框。这有什么区别吗?

1 个答案:

答案 0 :(得分:1)

嗯,你的商船拼写错误了,但看起来你在这两个地方拼错了。另外,你有一个递归循环,你的计算属性需要自己,我假设你打算在计算属性中使用shipCommercial而不是shipType

模板

<label>{{input type='checkbox' checked=shipCommercial}} Check Me </label>

属性

shipCommercial:true,
shipType: function() {
  var shipCommercial = this.get('shipCommercial');
  return shipCommercial ? 0 : 1;
}.property('shipCommercial')

实施例

http://emberjs.jsbin.com/zimopise/1/edit

相关问题