I've been working on implementing tagging with rails and ember, based on this railscast: http://railscasts.com/episodes/382-tagging
I've setup an ember-data model with a tagList
property, which I'd like to set every time a tag changes (using the following setTagList
method):
App.Post = DS.Model.extend({
tags: DS.hasMany('App.Tag'),
tagList: DS.attr('string'),
setTagList: function() {
if(this.get('tags.length')) {
var tagList = this.get('tags').map(function(tag) {
return tag.get('name');
}).join(', ');
this.set('tagList', tagList);
}
}.observes('isLoaded', 'tags', 'tags.@each.name')
});
The first error I ran into was:
Uncaught TypeError: Cannot call method 'send' of null
Which I believe is as a result of observing tags
and tags.@each.name
. I've also read that there may be issues with observing nested properties.
Secondly, by removing those dependencies to leave .observes('isLoaded')
, the following error is thrown:
Uncaught Error: Attempted to handle event `materializingData` on <App.Post:ember283:1> while in state rootState. Called with undefined
Which is caused by any call to this.get('tags')
.
See the JSBin: http://jsbin.com/iyoyax/7/edit
Can anyone advise how I might observe an associated model to set another attribute on the same model?
Thanks in advance