1 に答える
0
selectBox
dom 要素とプラグイン自体の両方が既にアクティブに更新されているため、value changer をリッスンする必要はありません。オブザーバーの単純なトレースはvalueChanged
、多くのことを教えてくれます。
あなたの質問に基づいて、この小さなスニペットが出てきます。実際、私はそれが実際にあなたの元の方法のようだと思います.
Ember.Select.reopen({
didInsertElement: function(){
this.set('value', null);
this.$().selectBox(); // Create the jQuery plugin
},
contentChanged: function() {
//Ember.run.next is equivalent to setTimeout(fn,1);
//We want to wait for contentChanged first to finish
//then rerender selectBox.
//To get the structure of key-value is too tedious so
//just rerender it instead.
Ember.run.next(this, function() {
this.$().selectBox('refresh');
});
//Reset the selection value if you insist
//this.set('value', null);
}.observes('content')
});
setTimeout
最初にコンテンツがレンダリングされるのを待つ必要があるので、それだけで大丈夫だと思います。リフレッシュは重すぎてはいけません。
于 2013-02-16T16:19:11.513 に答える