问题描述
处理具有事件
和每个事件
的应用程序有许多图像
Working on an app that has events
and each event
has many images
这是协会:
图片:DS。 hasMany(event-image,{async:true})
EventImage
Model:
`import DS from 'ember-data'`
EventImage = DS.Model.extend
event: DS.belongsTo("event")
### NATURAL ATTRIBUTES ###
imageUrl: DS.attr("string", { defaultValue: "" })
fileName: DS.attr("string")
fileSize: DS.attr("string")
primary: DS.attr("boolean", { defaultValue: false })
featured: DS.attr("boolean", { defaultValue: false })
`export default EventImage`
当访问 / events / 1722 / edit
时,我试图显示如下图像:
When visiting /events/1722/edit
, I am [trying to] display the images like so:
<div class="field">
<label class="label label__text">More images</label>
{{#core-image-multiple-uploader model=model processedFiles=model.images}}
Select additional event photos (10 max).
{{/core-image-multiple-uploader}}
</div>
JSON API响应返回的属性如下:
The JSON API response, returns an attribute that looks like:
"image_ids": [
2474,
2469,
2468
]
当页面加载时,我可以看到页面上的三个图像,但是当尝试获取数据以加载每个图像时,API路由被调用的是 / api / event_images / 2469
。我需要添加在 event_id
查询参数(或者甚至更好, event_images
嵌套在事件下面,使API调用 / events /:event_id / event_images
)。
When the page loads, I can see the three images on the page, but when attempting to fetch data to load each image, the API route that is called is /api/event_images/2469
. I need to add on the event_id
query param (or even better, have event_images
nested underneath events so that the API call is /events/:event_id/event_images
).
我在 EmberJS v1。 10
,并使用 ActiveModelAdapter
。这看起来像这样:
I am on EmberJS v1.10
and am using ActiveModelAdapter
. That looks like this:
`import Ember from 'ember'`
`import DS from 'ember-data'`
ApplicationAdapter = DS.ActiveModelAdapter.extend
host: window.EmberENV.apiURL
headers:
"Accept" : "application/json, text/javascript; q=0.01"
`export default ApplicationAdapter`
我是一个EmberJS新手,投入这个项目,所以我在这里道歉,试图赶上。
I'm an EmberJS newb, dropped into this project, so my apologies here, trying to play catch up.
推荐答案
if u想要一个不同的请求url然后常规。然后U可以写一个单独的适配器为那个模态。
if u want a different request url then conventional.then U can write a separate adapter for that modal. you have override
From EmberJS Docs
From EmberJS Docs
buildURL (modelName, id, snapshot, requestType, query) String
Inherited from DS.BuildURLMixin addon/-private/adapters/build-url-mixin.js:33
Builds a URL for a given type and optional ID.
By default, it pluralizes the type's name (for example, 'post' becomes 'posts' and 'person' becomes 'people'). To override the pluralization see pathForType.
If an ID is specified, it adds the ID to the path generated for the type, separated by a /.
When called by RESTAdapter.findMany() the id and snapshot parameters will be arrays of ids and snapshots.
Parameters:
modelName String
id (String|Array|Object)
single id or array of ids or query
snapshot (DS.Snapshot|Array)
single snapshot or array of snapshots
requestType String
query Object
object of query parameters to send for query requests.
Returns:
String
url
这篇关于EmberJS有多个关联提取无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!