带有变量的jQuery .each()

时间:2016-02-10 20:17:25

标签: javascript jquery variables each

我正在尝试使用变量(data。$ choice)代替(data.client_kits_bios)来迭代数组。

我猜不能在那里放置一个字符串变量?替换它会有什么选择?或者那是不可能的?

谢谢!

$( document ).ready(function() {

    var $choice = 'client_kits_bios';
    console.log($choice);

    $.ajax({
        url: 'data_marketingLibrary.json',
        dataType: 'json',
        type: 'get',
        cache: false,
        success: function(data) {
            $(data.$choice).each(function(index, value) {
                console.log(value.name);
                console.log(index);
            });
        }
    });
});

0 个答案:

没有答案