我已经完成了与 Chosen 的示例 Ember.js 集成(https://github.com/harvesthq/chosen)
咖啡脚本:
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")))))
})
困扰我的事情是我不知道在触发选择小部件上的更新之前我需要多少时间。根据我的实验,2 个运行循环是可以的,但也许有更好的方法来处理整个事情?
jsfiddle 的完整示例:http: //jsfiddle.net/oruen/qfYPy/