[英]Update the value of a field in a JSON object using Jquery
I have a JSON object: 我有一个JSON对象:
[{"file":"post_files/feb641027629b6a7ba78fb47063c6763vid.flv","title":"Sample"},
{"file":"post_files/74c73cf0e28d6ca431ab4c2e2299f39fbarsandtone.flv","title":"Bars"}]
As you can see, file
fields have values like post_file/feb.................flv
. 如您所见,
file
字段具有诸如post_file/feb.................flv
。
All I want is to append http://divinotech.in/
to all the file
fields' values, ie the value should get edited like this: 我想要做的就是将
http://divinotech.in/
附加到所有file
字段的值,即该值应像这样进行编辑:
http://divinotech.in/post_file/feb.................flv
How can I do this? 我怎样才能做到这一点?
You could loop through the elements of the array and modify the file
property: 您可以遍历数组的元素并修改
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
Try this 尝试这个
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>');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.