Chosen (https://github.com/harvesthq/chosen) との Ember.js 統合のサンプルを作成しました。
コーヒースクリプト:
App.ChosenSelectView = Em.Select.extend({
didInsertElement: ->
@_super()
@$().chosen()
# Assumes optionLabelPath is something like "content.name"
@addObserver(@get("optionLabelPath").replace(/^content/, "content.@each"), -> @contentDidChange())
contentDidChange: ->
# 2 ticks until DOM update
Em.run.next(this, (-> Em.run.next(this, (-> @$().trigger("liszt:updated")))))
})
私を悩ませているのは、Chosen ウィジェットの更新をトリガーする前に、どのくらいの時間が必要かについてよくわからないことです。私の実験から、2回の実行ループは問題ありませんが、全体にもっと良い方法があるのでしょうか?
jsfiddle の完全な例: http://jsfiddle.net/oruen/qfYPy/