0

有谁知道如何修改 JSON 数组中的标签?

可以说我的数组是:

[{"Device_ID":"43","Image":"Amazon-Kindle-Fire.png","Manufacturer":"Amazon","Model":"Kindle Fire","Type":"Tablet"},{"Device_ID":"43","Image":"Apple-iPad.png","Manufacturer":"Apple","Model":"iPad","Type":"Tablet"}]

如何操作它,以便 Device_ID 成为标签,制造商和型号的组合成为值?

这是 jquery 自动完成所必需的,我无法在源代码中修改当前 JSON 数组

更新:

目前尝试这种方式没有成功:

$(function() {
    var availableTags = <?php echo json_encode($results); ?>;
    var john = availableTags.forEach(function(v){v.Device_ID = v.Manufacturer + v.Model});
    $("#search_input").autocomplete({
        source: john;
    }); 
});
4

1 回答 1

0

试试看:

o = [{"Device_ID":"43","Image":"Amazon-Kindle-Fire.png","Manufacturer":"Amazon","Model":"Kindle Fire","Type":"Tablet"},{"Device_ID":"43","Image":"Apple iPad.png","Manufacturer":"Apple","Model":"iPad","Type":"Tablet"}]
o.forEach(function(v){v.Device_ID = v.Manufacturer + " " + v.Model})

它将循环遍历数组中的每个对象,并将 id 分配给您需要的组合。

于 2012-10-04T09:13:59.560 回答