EmberJS - classNameBindings w / Observe&财产未更新/解雇

时间:2014-06-28 18:32:31

标签: ember.js

这是一个非常基本的问题,我一直试图弄清楚无济于事。我正在将Google地图与EmberJS集成,并尝试在IndexController中由另一个视图设置的属性上执行classNameBindings。值正确更新,但不会触发。我已尝试过两种属性(' controller.panoEnabled')和.observes(' controller.panoEnabled')。没有火......任何想法?非常感谢帮助,我为这个基本问题道歉。

JSBin:http://emberjs.jsbin.com/degivubu/4/edit

2 个答案:

答案 0 :(得分:1)

我建议isEnabled:Em.computed.alias('controller.panoEnabled')提供Duncan Walker提到的第二个选项,因为binding后缀的属性已经被“软”弃用(https://github.com/emberjs/ember.js/issues/1164#issuecomment-23200023)。

App.PanoView = Ember.View.extend({
  classNames: ['pano'],
  classNameBindings: ['isEnabled'],
  /*isEnabled:function(){
    return this.get('controller.panoEnabled');
  }.property('controller.panoEnabled')*/
  isEnabled:Em.computed.alias('controller.panoEnabled')
});

还需要在google地图相关代码中修复this的上下文,如下所示

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

....
 var self = this;
    google.maps.event.addListener(marker, 'click', function(){
       self.set('controller.panoEnabled',true); 
      console.log( self.get('controller.panoEnabled') ); });
    google.maps.event.addListener(map, 'click', function(){ 
      self.set('controller.panoEnabled', false); 
      console.log( self.get('controller.panoEnabled') ); });
....

答案 1 :(得分:0)

尝试:

App.PanoView = Ember.View.extend({
  classNames: ['pano'],
  classNameBindings: ['isEnabled'],
  isEnabled: function(){
    return this.get('controller.panoEnabled');
  }.property('controller.panoEnabled'),
});

App.PanoView = Ember.View.extend({
  classNames: ['pano'],
  classNameBindings: ['isEnabled'],
  isEnabledBinding: 'App.IndexController.panoEnabled',
});