下面的代码工作得很好,除了我在附加从JSON 多维数组动态检索的元素时得到的令人讨厌的未定义。我无法弄清楚它来自哪里,但是,我假设它来自在函数外部声明一个变量并在内部使用它来积累数据。$.each()
var c = 0;
var q = 1;
$.each(json, function (i, data) {
var answers; // declared here and outside this function - same results.
$.each(data.answers, function (i, a) {
answers += '<tags>' + a + '</tags>'; // the problem is here "maybe".
});
$('.foo').append(answers); // I get "undefined" ahead of values retrieved.
});