我正在尝试实现“关注/关注”关系。
应用程序/模板/users.hbs----------------------------------------
{{#each model as |user|}}
...
<button {{action 'follow' user}}>Follow</button>
{{/each}}
app/routes/user.js----------------------------------------
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);
},
app/models/user.js------------------------
...
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' },
关于javascript - Ember.Js 反射协会,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41598848/