无法获得与ember数据相关的关系(Cannot get relationships working with ember data)

编程入门 行业动态 更新时间:2024-10-24 14:17:30
无法获得与ember数据相关的关系(Cannot get relationships working with ember data)

我正在使用RESTAdapter的ember-data。

我有一个旅游模块:

DS.Model.extend({ title: DS.attr('string'), trips: DS.hasMany('trip') });

这是用REST json填充的:

[{ id: 132, title: 'Tour title', },...]

Trips的模块:

DS.Model.extend({ tour: DS.belongsTo('tour'), startDate: DS.attr('date') });

这是用REST json填充的:

{ id: 12345, tour_id: 132, startDate: '2013-01-01', }

我想这样,当使用旅行模型时,我可以打电话给trip.tour.title来获得旅行的标题。 分别我可以制作tour.trips以获得所有旅行的列表。

但不知何故,这不起作用任何关系用法甚至不会触发ajax请求。 所以我想知道为什么? 所有属性都已正确映射,但不是关系。

请指教。

I am using ember-data with RESTAdapter.

I have a module for Tours:

DS.Model.extend({ title: DS.attr('string'), trips: DS.hasMany('trip') });

this is populated with REST json:

[{ id: 132, title: 'Tour title', },...]

and a module for Trips:

DS.Model.extend({ tour: DS.belongsTo('tour'), startDate: DS.attr('date') });

this is populated with REST json:

{ id: 12345, tour_id: 132, startDate: '2013-01-01', }

I would like so that that when using trip model I could call trip.tour.title to get a title of the tour. And respectively I could make tour.trips to get a list of all trips for the tour.

But somehow this is not working any relationships usage don't even trigger an ajax request. So I wonder why? All the properties are mapped correctly, but not relationships.

Please advice.

最满意答案

好像它是这个库的旧版本,这已不相关了。

Seems like it was an old version of this libs, this is not relevant anymore.

更多推荐

本文发布于:2023-07-16 10:00:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1126861.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:关系   数据   ember   data   working

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!