ember-data不支持嵌入对象 [英] ember-data does not support embedded objects

查看:85
本文介绍了ember-data不支持嵌入对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用垃圾数据rev-11和django tastypie。看来,现在ember数据不支持嵌入式资源,但支持sideloads(django tastypie不支持)。什么是最好的解决方案?



谢谢

解决方案

对于Ember Data 1.0 beta +有效,请参阅重复的答案



Ember数据仍然支持嵌入式。你只需要正确的配置。这里你可以如何做:

  DS.RESTAdapter.map('App.Foo',{
bar: {
embedded:'always'
}
})

App.Foo = DS.Model.extend({
bar:DS.belongsTo App.Bar,{embedded:'always'}),
});

嵌入式可用值为:始终加载


加载:加载时嵌入子记录,但应将
保存为独立记录。为了这个工作,孩子记录
必须有一个ID。



始终:加载时子嵌入,并保存
嵌入同一条记录。这当然会影响
的肮脏记录(如果子记录更改,适配器会将
父记录标记为脏)。


类似的设置适用于HasMany关系,有关详细信息,请参阅此回复


i'm working with ember data rev-11 and django tastypie. Looks like now ember-data does not support embeded resources but support sideloads (django tastypie does not support it). What is the best solution?

Thanks

解决方案

This is not valid for Ember Data 1.0 beta+, see duplicate answer

Ember-data still supports embedded. You just need the right configuration. Here how you can do it:

DS.RESTAdapter.map('App.Foo',{
    bar:{
        embedded:'always'
    }
})

App.Foo = DS.Model.extend({
    bar: DS.belongsTo(App.Bar,{embedded:'always'}),
});

Available values for embedded are: always and load.

load: The child records are embedded when loading, but should be saved as standalone records. In order for this to work, the child records must have an ID.

always: The child records are embedded when loading, and are saved embedded in the same record. This, of course, affects the dirtiness of the records (if the child record changes, the adapter will mark the parent record as dirty).

Similar settings apply for HasMany relationship, see this reply for more details

这篇关于ember-data不支持嵌入对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆