本文介绍了EmberJS - classNameBindings w / Observe&物业不更新/开火的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个非常基本的问题,我一直在努力解决这个问题。我将Google Maps与EmberJS集成,并尝试在IndexController中由另一个视图设置的属性上执行classNameBindings。值正确更新,但不会触发。我已经尝试过两个属性('controller.panoEnabled')以及.observes('controller.panoEnabled')。没有任何想法?帮助是非常感激的,我为这个基本的问题道歉。

This is a really basic question and I've been trying to figure it out to no avail. I'm integrating Google Maps with EmberJS and trying to do classNameBindings on a property within the IndexController that is being set by another view. The values get updated properly, but it doesn't fire. I've tried both property('controller.panoEnabled') and also .observes('controller.panoEnabled'). Neither fires... any idea? Help is much appreciated and I apologize for this rudimentary question.

JSBin:

推荐答案

对于Duncan Walker提到的第二个选项,我建议 isEnabled:Em.computed.alias('controller.panoEnabled'),作为绑定后缀已被轻轻地弃用()。

I would advise isEnabled:Em.computed.alias('controller.panoEnabled') for the second option mentioned by Duncan Walker, as the property with the binding suffix has been 'softly' deprecated (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地图相关的代码如下所示

Also it is needed to fix the context of this in the google maps related code as shown below

....
 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') ); });
....

这篇关于EmberJS - classNameBindings w / Observe&物业不更新/开火的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 07:24