So i am trying to dynamically add these observer methods to a Ember.js object
holderStandoutCheckedChanged: (->
if @get("controller.parent.isLoaded")
@get("controller").toggleParentStandout(@get("standoutHolderChecked"))
).observes("standoutHolderChecked")
holderPaddingCheckedChanged: (->
if @get("controller.parent.isLoaded")
@get("controller").toggleParentPadding(@get("holderPaddingChecked"))
).observes("holderPaddingChecked")
holderMarginCheckedChanged: (->
if @get("controller.parent.isLoaded")
@get("controller").toggleParentMargin(@get("holderMarginChecked"))
).observes("holderMarginChecked")
I have this code so far but the item.methodToCall function is not getting called
methodsToDefine = [
{checkerName: "standoutHolderChecked", methodToCall: "toggleParentStandout"},
{checkerName: "holderPaddingChecked", methodToCall: "toggleParentPadding"},
{checkerName: "holderMarginChecked", methodToCall: "toggleParentMargin"}
]
add_this = { }
for item in methodsToDefine
add_this["#{item.checkerName}Changed"] = (->
if @get("controller.parent.isLoaded")
@get("controller")[item.methodToCall](@get(item.checkerName))
).observes(item.checkerName)
App.ColumnSetupView.reopen add_this
Can anyone tell me what i am doing wrong ? Is there a better way to do this ? Should i be doing this in a mixin ? If so please
I don't know your exact use case, but as you said, your described problem could be solved with a Mixin, see http://jsfiddle.net/pangratz666/a3Usx/
JavaScript:
Sample use case:
Another implementation would be a mixin which uses an array
watchProperties
, which is a list of properties which shall be observed, see http://jsfiddle.net/pangratz666/bSF3Z/:JavaScript: