Javascript 余烬反射联想
我试图实现“跟随者/跟随者”关系 app/templates/users.hbs---------------------------Javascript 余烬反射联想,javascript,ember.js,Javascript,Ember.js,我试图实现“跟随者/跟随者”关系 app/templates/users.hbs--------------------------- {{#each model as |user|}} ... <button {{action 'follow' user}}>Follow</button> {{/each}} follow(user){ //currentUser is the one clicking on 'follow' button
{{#each model as |user|}}
...
<button {{action 'follow' user}}>Follow</button>
{{/each}}
follow(user){
//currentUser is the one clicking on 'follow' button
//and it works.I can successfully alert it's properties.
currentUser.get('followings').pushObject(user);
},
...
followings: DS.hasMany('user',{inverse: null}),
followers: DS.hasMany('user',{inverse: null}),
app/models/user.js-----------------------
{{#each model as |user|}}
...
<button {{action 'follow' user}}>Follow</button>
{{/each}}
follow(user){
//currentUser is the one clicking on 'follow' button
//and it works.I can successfully alert it's properties.
currentUser.get('followings').pushObject(user);
},
...
followings: DS.hasMany('user',{inverse: null}),
followers: DS.hasMany('user',{inverse: null}),
现在,这个解决方案导致了下面的错误
Uncaught TypeError: Cannot read the property 'modelName' of undefined at assertPolymorphicType.notifyRecordRelationshipAdded
试试这个:
followings: DS.hasMany('user', { inverse: 'followers' },
followers: DS.hasMany('user', { inverse: 'followings' },
试试这个:
followings: DS.hasMany('user', { inverse: 'followers' },
followers: DS.hasMany('user', { inverse: 'followings' },