我有一个JSON对象:
[{"file":"post_files/feb641027629b6a7ba78fb47063c6763vid.flv","title":"Sample"},
{"file":"post_files/74c73cf0e28d6ca431ab4c2e2299f39fbarsandtone.flv","title":"Bars"}]
如您所见,file
字段的值为post_file/feb.................flv
。
我想要的只是将http://divinotech.in/
附加到所有file
字段'值,即值应按此编辑:
http://divinotech.in/post_file/feb.................flv
我该怎么做?
答案 0 :(得分:3)
您可以循环遍历数组的元素并修改file
属性:
var array = [
{ "file": "post_files/feb641027629b6a7ba78fb47063c6763vid.flv", "title":"Sample"},
{ "file": "post_files/74c73cf0e28d6ca431ab4c2e2299f39fbarsandtone.flv", "title":"Bars"}
];
for (var i = 0; i < array.length; i++) {
array[i].file = 'http://divinotech.in/' + array[i].file;
}
// at this stage the array will contain the desired values
这是一个live demo
。
答案 1 :(得分:0)
试试这个
var result=[{"file":"post_files/feb641027629b6a7ba78fb47063c6763vid.flv","title":"Sample"},
{"file":"post_files/74c73cf0e28d6ca431ab4c2e2299f39fbarsandtone.flv","title":"Bars"}]
for (var i in result) {
$("body").append('<a href="http://divinotech.in/'+result[i].file+'">'+result[i].title+'</a></br>');
}