1
クライアントAPIからデータが返されています。 私は彼らにそれを変更させる能力がありません。彼らはそれを明確にしました。標準化されたデータ構造を作成するためにnormalizrおよび/またはimmutablejを使用する方法
{
"feed": {
"name": "name",
"media:destination": "http...",
"channel": {
"pagecomponent": {
"component": [{
"item": {
"link": "http...",
"description": "description",
"title": "title",
"category": "tag 2",
"pubDate": "2002-01-01T20:00:00.000Z",
"media:content": {
"medium": "image",
"url": "http..."
}
}
}, {
"item": {
"link": "",
"info:pagecomponent": {
"id": "1237",
"content": "na"
},
"description": "description",
"title": "title",
"category": "tag 1",
"pubDate": "2007-01-21T20:00:00.000Z",
"media:content": {
"media:restriction": [{
"relationship": "allow",
"type": "country",
"content": "us ca"
}, {
"relationship": "allow",
"type": "url",
"content": "?"
}],
"media:description": "title",
"media:thumbnail": {
"width": "",
"url": "http...",
"height": ""
},
"media:title": "title",
"medium": "video",
"type": "application/x-mpegURL",
"url": "http..."
}
}
}]
}
}
}
ほとんどの最初の数層はほとんど変更されず、UIには影響しません。私はnormalizrを使用していくつかのバリエーションを試しましたが、何もリモートでは動作しません。私にとって重要なデータは「コンポーネント」レベルにあります。最終的に、私は気に唯一のデータは、「コンポーネント」キーから「アイテム」の配列である:
item: {
id: null,
link: null,
description: null,
title: null,
pubDate: null,
category: null,
thumbnailWidth: null,
thumbnailUrl: null,
thumbnailHeight: null,
medium: null,
contentTypeHeader: null,
videoUrl: null,
"media:content": mediaInfo,
"media:restriction": restrictions
}
これは最初のアプローチする最良の方法のように見えます。 Normalizrはネストされたデータ(エンティティ内にエンティティを持つ可能性がある場所)に最適です。与えられたデータは、唯一の問題のように見えます。必要なデータがトップレベルよりも深い場合があります。 ImmutableJSはあなたが求めていることに対して何もしません。 –