Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/378.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jsonpatch数组中的所有元素_Javascript_Json - Fatal编程技术网

Javascript jsonpatch数组中的所有元素

Javascript jsonpatch数组中的所有元素,javascript,json,Javascript,Json,下面的帖子让我使用jasonpatch进行json到json的转换: 可在以下位置找到该项目: 我目前正在尝试更改数组中所有元素的名称,但不知道这是如何实现的。我目前的尝试是: var transformations = [ { op: 'move', from:'/hits/1/_id', path: '/hits/1/pizza'} ]; 这将交换出第一个元素,但如何执行“*”卡类型的操作?比如: var transformations = [ { op: 'move', from:'

下面的帖子让我使用jasonpatch进行json到json的转换:

可在以下位置找到该项目:

我目前正在尝试更改数组中所有元素的名称,但不知道这是如何实现的。我目前的尝试是:

var transformations = [
{ op: 'move', from:'/hits/1/_id', path: '/hits/1/pizza'}
];
这将交换出第一个元素,但如何执行“*”卡类型的操作?比如:

var transformations = [
{ op: 'move', from:'/hits/*/_id', path: '/hits/*/pizza'}
];

我可以看到可能会为每个元素调用N次转换,但这看起来像是一个黑客行为。

最终使用了一种方法,我将调用包装成一个循环:

 for(i=0;i<json.hits.length;i++) {
    var transformations = [{ op: 'move', from:'/hits/'+i+'/_id', path:'/hits/'+i+'/pizza'}];
    var result = jsonpatch.apply(json,transformations);             
 }
(i=0;i)的