javascript - Generate methods at runtime in emberJS -
im trying generate few methods @ runtime in ember , code i'm trying is
app.testcontroller = ember.arraycontroller.extend app.anothermixin,    unsubmitted: em.computed.filterby("model", "unsubmitted", true)   submitted: em.computed.filterby("model", "submitted", true)   canceled: em.computed.filterby("model", "canceled", true) # rather using above methods i'm trying generate them meta-programming.    that: @   defineattributes: (->     [       "unsubmitted"       "submitted"       "cancelled"     ].foreach ( f ) ->       em.defineproperty , f, em.computed.filterby("model", f, true)       return     return   ).on("init")   but not generating methods. there im missing?
you're defining that property on controller, trying use local variable in defineattributes method. change that local variable in method , should work fine. or better yet, use coffeescript's fat arrow function maintain current value of this:
defineattributes: (->     ['unsubmitted', 'submitted', 'cancelled'].foreach (f) =>         em.defineproperty this, f, em.computed.filterby('model', f, true) ).on('init')      
Comments
Post a Comment