我有json字符串,由server.php
生成[{"attr":{"id":"node_7","rel":"default"},"data":"doc.html","state":""},
{"attr":{"id":"node_8","rel":"folder"},"data":"New node","state":"closed"},
{"attr":{"id":"node_9","rel":"folder"},"data":"New node","state":""}]
如何删除包含值rel=default
这是我为server.php。
编写的代码require_once("config.php");
$jstree = new json_tree();
echo $jstree->{$_REQUEST["operation"]}($_REQUEST);
die();
答案 0 :(得分:1)
使用PHP:
// convert json string to array
$json = json_decode($json_string);
// filter out items
$json = array_filter($json, function($item)
{
return $item->attr->rel != "default";
});
// convert back to string
$json_string = json_encode($json);
答案 1 :(得分:0)
您可以使用data.items.splice(X,Y);删除元素;)