处理具有events
且每个event
的应用有images
以下是协会:
images: DS.hasMany("event-image", { async: true })
EventImage
模型:
`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
时,我[尝试]显示图像:
<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响应,返回如下所示的属性:
"image_ids": [
2474,
2469,
2468
]
当页面加载时,我可以在页面上看到三个图像,但在尝试获取数据以加载每个图像时,调用的API路径为/api/event_images/2469
。我需要添加event_id
查询参数(或者甚至更好,将event_images
嵌套在事件下面,以便API调用为/events/:event_id/event_images
)。
我正在EmberJS v1.10
并正在使用ActiveModelAdapter
。看起来像这样:
`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 newb,投入到这个项目中,所以我在这里道歉,试图追赶。
答案 0 :(得分:0)
如果你想要一个不同的请求url然后常规。那么你可以为该模态编写一个单独的适配器。你有覆盖
适配器中的buildUrl方法
来自EmberJS文档
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