简体   繁体   English

Ember.js如何通过视图Ember观察选择变化。选择倍数=真?

[英]Ember.js How to observe selection changes with view Ember.Select multiple=true?

I've tried to observe selection change for simple Ember.Select and it works, but when I use select with multiple=true it fails. 我试图观察简单Ember.Select的选择更改并且它可以工作,但是当我使用select with multiple = true时它会失败。 Here some code: 这里有一些代码:

 {{view Ember.Select
 multiple=true
 contentBinding="App.TopicController"
 selectionBinding="content.TOPICS"
 optionLabelPath="content.label"
 optionValuePath="content.id"}}

When I change selection on my input it must trigger observer: 当我更改输入的选择时,它必须触发观察者:

App.Configuration = Em.Object.extend({
    TOPICS:[],

  // this observer must work when selection changes
  topicsSelected: function() {
    console.log('topics selection changed!');
  }.observes('TOPICS', 'TOPICS.@each', 'TOPICS.length')

});

JSBin with this problem: http://jsbin.com/ JSBin有这个问题: http//jsbin.com/

Versions : handlebars 1.0.0, ember 1.0.0 版本 :车把1.0.0,ember 1.0.0

Changing the TOPICS variable to topics will solve this problem. TOPICS变量更改为topics将解决此问题。 I think this happen because this problem https://github.com/emberjs/ember.js/issues/3098 . 我认为这是因为这个问题https://github.com/emberjs/ember.js/issues/3098

In your topicsSelected observer if you want to observe the selection just observes('topics.length') is needed. 在您的topicsSelected观察者中,如果您想观察选择,则需要observes('topics.length')

Give a look in your updated jsbin http://jsbin.com/ofONeQ/14/edit 看看你更新的jsbin http://jsbin.com/ofONeQ/14/edit

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM