cook-nested 是一个针对嵌套结构数据提供 新增,删除,更新,选择
操作的库
import cookNestedData from 'cook-nested';
cookNestedData(originData, {
type: 'INSERT',
id: '2',
data: {}
});
import cookNestedData from 'cook-nested';
cookNestedData(originData, {
type: 'DELETE',
id: '1'
});
import cookNestedData from 'cook-nested';
cookNestedData(originData, {
type: 'UPDATE',
id: '1',
data: {}
});
import cookNestedData from 'cook-nested';
cookNestedData(originData, {
type: 'SELECT',
id: '1'
});
// 删掉id=1的元素然后在id=2的元素后插入新的data
import cookNestedData from 'cook-nested';
cookNestedData(
originData,
{
type: 'DELETE',
id: '1'
},
{
type: 'INSERT',
id: '2',
data: {}
}
);