我试图使用USERBOX插件,在这个例子中,我们有以下阵列正在兴建的Javascript转换为例,真正的代码问题 - 阵列
var data = [
{text: "Adam Adamson", id: "[email protected]"},
{text: "Betsy Boop", id: "[email protected]"},
{text: "Jooles Jooles", id: "[email protected]"}
];
我要建立使用JSON我在运行时数组我从我的web服务收到的数据。 在我的代码中,我试图用下面的方法来模仿这个数组。
var data = new Array();
for (var i = 0; i < msg.d.ListExercise.length; i++) {
$("userlist").append("msg.d.ListExercise[i].exercise_value");
if (i > 0 && i < msg.d.ListExercise.length - 1) {
data.push('{text: ' + '"' + msg.d.ListExercise[i].exercise_value + '"' + ' , id: ' + '"' + msg.d.ListExercise[i].exercise_id + '"' + '},');
}
if (i == msg.d.ListExercise.length - 1) {
data.push('{text: ' + '"' + msg.d.ListExercise[i].exercise_value + '"' + ' , id: ' + '"' + msg.d.ListExercise[i].exercise_id + '"' + '}');
}
}
从我所了解的例子中他建立了一个字符串数组。我已经验证数组正在被添加到数据并且数据正在被添加到它。但是,当我将数组传递给插件代码时,它显示单词'Undefined'135次(数组的长度)。
我的数组看起来是这样的:
{text: "Standard Push-Up" , id: "1"},
{text: "Wide Front Pull-Up" , id: "2"},
{text: "Vertical Punches" , id: "135"}
是什么让我的数据到在JavaScript他的阵列例子的最佳方式?
丢失单引号。你现在正在推弦乐,而不是对象 – mplungjan 2010-10-31 17:12:40
@mplungjan - 谢谢,你是对的! – webdad3 2010-10-31 17:33:39