【发布时间】:2012-04-01 20:50:05
【问题描述】:
我已经完成了与 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/
【问题讨论】: