【发布时间】:2017-01-29 16:31:49
【问题描述】:
我有一个 api 客户端,可以很好地从网站中的 Json 获取信息。我想要的是在从网站获取后向该内容包添加一些新行。
我了解了 .push 函数,但不知道在哪里放入新的 ES6 格式,也无法在 Google 中找到任何信息。
我正在使用:
react-native-cli: 2.0.1
react-native: 0.40.0
这是代码:
const BASE_URL = 'https://example.com/data.json';
customData = [
{
autor: 'Mike',
category: 'category name',
}
]
function getJsonData() {
return fetch(BASE_URL)
.then(response => response.json())
.then(data => data.items.item)
.then(myData => myData.push(customData)) // <- Trying to add custom data
.then(news => news.map(item => {
return {
autor: item.author,
category: item.category,
}
})
)
//.then(news => news.push(customData)) // <- Also I tried here
}
export { getJsonData }
【问题讨论】:
标签: json react-native fetch