reqI有一个像这样的json:
[{"type":"checkbox",
"title":"An example",
"values":
{"2": {"value":"val1", "required":"true"},
"3": {"value":"val2", "required":"false"},
"4": {"value":"val3", "required":"false"},
}
}, and so on]
我有一个jquery函数
var fromJson = function (json) {
var values = '';
var options = false;
// Parse json
$(json).each(function () {
// type "checkbox"
if (this.type === 'checkbox') {
options = [this.title];
values = [];
$.each(this.values, function () {
values.push([this.value, this.required]);
});
}
// other types
...
});
};
我会$.each(this.values, function () {
values.push([this.value, this.baseline]);
});
按正确的顺序推送值,我该怎么办?
有没有办法根据“2”,“3”,“4”等命令values
......在做推动之前?
修改
我已经解决了
$.each(this.values, function (key) {
values[key-2]=[this.value, this.required];
});