在Ember.js中的脏对象上设置belongsTo关系 [英] Setting a belongsTo Relationship on a Dirty Object in Ember.js
本文介绍了在Ember.js中的脏对象上设置belongsTo关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Whistlr.Upload = DS.Model.extend
组织:DS.hasMany ('组织')
Whistlr.Organization = DS.Model.extend
上传:DS.belongsTo('upload')
用户通过Jquery文件上传在组织表单内创建上传。在成功回调中,我设置了如下关系:
upload = @get('parentView')。get ').store.createRecord('upload',response.upload)
@get('parentView')。get('controller')。set('upload',upload)
不幸的是,它被设置为 null
。这是因为我正在设法关系,而组织和上传实例都是脏的?
解决方案
你正在设置在控制器上上传,而不是在模型上。你可能想做:
@get('parentView')。get('controller.model'上传',上传)
I'm using Ember.js 1.0 and Ember-Data 1.0.0beta2. I have a couple of related models:
Whistlr.Upload = DS.Model.extend
organizations: DS.hasMany('organization')
Whistlr.Organization = DS.Model.extend
upload: DS.belongsTo('upload')
The user creates the Upload within the Organization form via Jquery File Upload. In the success callback, I set the relationship like so:
upload = @get('parentView').get('controller').store.createRecord('upload', response.upload)
@get('parentView').get('controller').set('upload', upload)
Unfortunately, it's getting set to null
. Is this because I'm trying to set the relationship while both the Organization and Upload instances are dirty?
解决方案
You're setting the upload on the controller instead of on a model. You probably want to do :
@get('parentView').get('controller.model').set('upload', upload)
这篇关于在Ember.js中的脏对象上设置belongsTo关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文