因此,在lodash
文檔這是我如何理解範圍,_.range(start, end)
。Javascript lodash範圍的數組JSON對象不返回
所以,如果我在一個JSON對象數組上使用.range()
。像...
const arr = [
{
name: 'name',
},
];
可以說,我有20個對象,我做arr._.range(5, 5);
我會從那裏拿回5 JSON對象和5。
所以我創建了一個地圖功能,讓我回JSON對象的列表,然後我用他們range
,這裏就是我有:
import R from 'lodash';
const getJsonData = (offset, limit) => (
R.map([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20], x => ({
title: `title ${x}`,
subtitle: 'description',
image_url: 'http://some-img-url.com',
date: 'date',
tag: 'tag',
places: [
{
places: 'places',
},
],
}), R.range(offset, (limit + offset)))
);
所以我把這種喜歡getJsonData(5, 5);
但它仍然給我回20個JSON對象的完整列表。
我誤解range
的工作原理嗎?
[有作爲 「JSON對象」 沒有這樣的事(http://benalman.com/news/ 2010/03/theres-no-such-thing-as-a-json /) – Andreas
@Andreas對不起,只是我的措辭不好。但一般jist是'.range()'不工作的問題,我不理解爲什麼 – PourMeSomeCode