Monday, 15 September 2014

ember.js - Ember - binding Ember.select in a component -



ember.js - Ember - binding Ember.select in a component -

i inherited ember project , have been learning go along. several questions deal ember.select bindings in controller/view context. im working in component context , having issues translating advice & help.

and may not need. goal have select menu alter based on select , vice versa. if user chooses measurementtype below should cut down units of measure (uoms) list of measurement type. if there no measurement type , user chooses uom measurement type should switch 1 used uom.

handlebars code:

{{! ############## }} {{! # meas. type # }} {{! ############## }} {{#unless hasmeasurementtype}} <td class='col-lg-1'><span class="label label-default">{{unbound attribute.measurementtype}}</span></td> {{else}} <td class='col-lg-1'> {{view em.select content=measurementtypes optionvaluepath="content.name" optionlabelpath="content.name" value=attribute.measurementtype }} </td> {{/unless}} {{! ############## }} {{! # uom # }} {{! ############## }} <td class='col-lg-1'> {{view em.select content=uoms optionvaluepath="content.name" optionlabelpath="content.name" value=attribute.uom }} </td>

coffee script:

app.numberattributecomponent = ember.component.extend( tagname: 'tr' attributebindings: ['data-id'] precisions: [0, 1, 2, 3, 4, 5, 6] 'data-id': ember.computed.oneway('attribute.id') 'hasmeasurementtype': false attributemeasurementtype: '' attributeuom: '' sethasmeasurementtype: (-> attribute = @.get('attribute') @.set('attributemeasurementtype', attribute.get 'measurementtype') console.log("mt: " + @get 'attributemeasurementtype') @.set('hasmeasurementtype', ember.isnone(@get 'attributemeasurementtype')) ).on("init") setattributeuom: (-> attribute = @.get('attribute') @.set('attributeuom', attribute.get 'uom') console.log("uom: " + @get 'attributeuom') ).on("init") setmeasurementtypelookup: (-> store = specx.__container__.lookup('store:main') store.find('measurementtype').then ((measurementtypes) => @set 'measurementtypes', measurementtypes ) ).on("init") getalluoms: (-> console.log("get uoms") attribute = @.get('attribute') store = specx.__container__.lookup('store:main') store.find('uom').then ((uoms) => @set 'uoms', uoms ) ) getuomsbymeasurementtype: (-> console.log("get uoms") attribute = @.get('attribute') store = specx.__container__.lookup('store:main') store.find('uom').then ((uoms) => @set 'uoms', uoms.filterby('measurementtype',attribute.get 'measurementtype') ) ) updateuom: (-> console.log("in updateuom") attribute = @get 'attribute' if ember.isnone(@get 'attributemeasurementtype') @.getalluoms() else @.getuomsbymeasurementtype() ).observes('attributemeasurementtype', 'attributeuom') # didinsertelement: -> # console.log("in didinsertelement") # attribute = @.get('attribute') # @set 'attributemeasurementtype', attribute.get 'measurementtype' # @set 'attributeuom', attribute.get 'uom' # console.log("new: " + attribute.get 'measurementtype' + "; " + attribute.get 'uom') # # willdestroyelement: -> # console.log("in willdestroyelement") # attribute = @.get('attribute') # @set 'attributemeasurementtype', attribute.get 'measurementtype' # @set 'attributeuom', attribute.get 'uom' actions: edit: -> @toggleproperty('isediting') save: -> model = @.get('attribute') editor = @ @.set('attributemeasurementtype', model.get 'measurementtype') @.set('attributeuom', model.get 'uom') model.save().then ((specification_attribute) => $.growl.notice title: "attribute", message: "attribute saved!" editor.toggleproperty('isediting') ) cancel: -> @toggleproperty('isediting')

ember.js

No comments:

Post a Comment