根据 URL 中的 ID 映射 RestKit 关系 [英] RestKit Relationship Mapping by ID in URL
问题描述
假设我在 users/1/items
有一个 API,它返回 ID 为 1 的 user
的 items
列表.
Assume I have an API at users/1/items
that returns a list of items
for the user
with an ID of 1.
假设 API 响应如下:
Assume the API response is as follows:
{
"items": [
{
"id": "1",
"description": "Some item"
}
]
}
请注意,响应不包含用于关系映射的 user_id
.在 RestKit 0.20 中是否可以映射到 URL 中的 user_id
(在这种情况下为 1)?如果是这样,如何?我在文档/维基中找不到任何提及.
Note that the response does not contain a user_id
for relationship mapping. Is it possible in RestKit 0.20 to map to the user_id
in the URL (in this case, 1)? If so, how? I could not find any mention of this in the docs/wiki.
推荐答案
是的.您需要使用 RKRouter
类(通常与 RKObjectManager
一起使用).使用路由和路径模式后,您可以在映射定义中使用路由元数据.
It is. You need to use the RKRouter
class (which you would usually use with RKObjectManager
). Once you're using routing and path patterns, you can use routing metadata in your mapping definitions.
如何使用元数据(元数据映射"部分)
这篇关于根据 URL 中的 ID 映射 RestKit 关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!