Ember.js: How to access a model's attributes inside Javascript code -
in ember.js while using ember-data
, can access model's attributes when in .hbs
template:
{{#each model |person|}} welcome, {{person.firstname}} {{person.lastname}}! {{/each}}
i tried accessing these values in javascript code (be inside controller or component) using following methods:
// method 1 if (person.firstname === 'jack') { // when first name jack } // method 2 if (person.get('firstname') === 'jack') { // when first name jack }
but none of these work attributes of current model. value can way id
of current model instance.
i have looked far , wide solution problem , found nothing, ask question:
is possible access attributes of model instance inside javascript code while using ember.js , ember-data? if so, how can done? if not, why can't that?
for reference, here current ember.js setup:
debug: ember : 2.5.1 debug: ember data : 2.5.3 debug: jquery : 2.2.4 debug: ember simple auth : 1.1.0
when have object you're passing component, becomes property of component. need object via component's property before accessing properties on model object itself.
assuming you're passing object component this:
{{person-profile person=person}}
either of these should work:
// method 3 if (this.get('person').get('firstname') === 'jack') { // when first name jack } // method 4 if (this.get('person.firstname') === 'jack') { // when first name jack }
Comments
Post a Comment