ember.js - How to come up with the global path to an Ember controller's property when value binding to a view helper? -
let's have following controllers
app.personcontroller = ember.objectcontroller.extend(); app.personstuffcontroller = ember.controller.extend({ somethingoncontroller: [] });
with router entries
this.resource('person', function() { this.route('stuff'); });
and routes
app.personroute = ember.route.extend({ model: function() { this.store.createrecord('person', {}); }, setupcontroller: function(controller, model) { controller.set('model', model); } }); app.personstuffroute = ember.route.extend({ model: function() { this.modelfor('person'); }, setupcontroller: function(controller, model) { controller.set('person', model); this.store.find('thing').then(function(things) { controller.set('things', things); }); } });
and models
app.thing = ds.model.extend({ name: ds.attr('string'), // instances of model have name values match person instance's property keys personstuffpath: function() { return 'person.' + this.get('name'); }.property('name') }); app.person = ds.model.extend({ // lot of attributes match names of app.thing instance name property values });
in template personstuff, have code
{{#each thing in things}} {{view ember.select content=somethingoncontroller value=thing.personstuffpath.value}} {{/each}}
so i'm expecting here bunch of input fields bound personstuffcontroller's person property's properties. instead error:
uncaught error: assertion failed: path 'person.examplethingname' must global if no obj given.
so modified thing model instead be:
app.thing = ds.model.extend({ name: ds.attr('string', { defaultvalue: 'thingname' }), personstuffpath: function() { return 'app.personstuffcontroller.person.' + this.get('name'); }.property('name') });
and error instead becomes:
uncaught error: property set failed: object in path "app.personstuffcontroller.person" not found or destroyed.
this should right global path, right? can not things way reason?
jsbins:
relative path error: http://jsbin.com/lozayobe/1/edit?html,js,output global path error: http://jsbin.com/lozayobe/2/edit?html,js,output
app.foocontroller
refers class, it's not actual instance. in cases ember controllers , routes singletons, aren't recreated (except item controllers). if wanted create global way of accessing controller need controller add global namespace.
for example (i'm not recommending this, it's understand how things work):
app.applicationcontroller = em.controller.extend({ beforemodel: function(){ var fooinstance = this.controllerfor('foo'); app.foocontrollerinstance = fooinstance; } });
now app.foocontrollerinstance
has instance of foocontroller
can map dynamic computed properties.
Comments
Post a Comment