我正在使用一个jQuery插件,该插件接受一个用户参数,该参数可以容纳多个用户,如:
$(elem).thePlugin({
user: [{name: 'username1', image: 'image1.jpg'},
{name: 'username2', image: 'image2.jpg'}]
});
但我想动态构建用户参数,以便我可以执行以下操作:
var userparam;
$('table.user tr').each(function() {
$name = $('td.name', this).html();
$image = $('td.img', this).html();
// add name and image to userparam
});
$(elem).thePlugin({
user: userparam
});
如何构建userparam var?
答案 0 :(得分:2)
var userparam = [];
$('table.user tr').each(function() {
$name = $('td.name', this).html();
$image = $('td.img', this).html();
// add name and image to userparam
userparam.push({ "name":$name, "image": $image });
});
$(elem).thePlugin({
user: userparam
});