我正在尝试动态创建一个JSON数组.在网站中,有一个动态数量的<div id ="#selected">,我需要获取所有值并创建一个JSON数组.
我遇到过.push()功能,但我无法弄明白.
<!-- there could be a million of these, or only one... each value is unique though -->
<div id="selected" value="5|3"></div>
<div id="selected" value="3|65"></div>
function json_array_selected() {
var JSon = {};
$('div#selected').each(function() {
// let's first split the given values
var Split = $(this).attr('value');
Split = Split.split('|');
var Type = Split[0];
Value = Split[1];
// now let's set up our Json array... using the value = type way, there should never be
// any repeating
JSon.Value = Type;
});
return JSon;
}
Run Code Online (Sandbox Code Playgroud)
代替
JSon.Value = Type;
Run Code Online (Sandbox Code Playgroud)
尝试
JSon[Value] = Type;
Run Code Online (Sandbox Code Playgroud)
或者你将永远覆盖一个名为"价值"的键
| 归档时间: |
|
| 查看次数: |
5743 次 |
| 最近记录: |