这是我解决这个问题的方法,但我很乐意接受任何提出更优雅解决方案的人。请原谅我的咖啡脚本
###
Add the property with the dynamic dependency key as a mixin after creating
the dependency key in the context of the object
###
init: ->
@_super()
mix = Ember.Mixin.create({
_fullName: (->
@get('key_from_runtime') #some logic on this key goes here
).property(key_from_runtime)
})
mix.apply(@)
@set('full_name_applied', true)
### Keep track of if the mixin has been applied ###
full_name_applied: false
### Depend on the shadow property that has the dynamic dependency key ###
fullName: (->
if _.isNull(@get('_fullName'))
'' #predefined blank value
else
@get('_fullName')
).property('_fullName', 'full_name_applied')