无法清理我的代码

时间:2012-03-26 16:31:09

标签: jquery

我有4个功能可以做我觉得可以做的事情。

function getDownline(rankid, args, type) {
    $('body').append('<div class="modal">');
    $.getJSON('message_center_getMessageLists.asp', args, function (json) {
        var options = '';
        $.each(json.downline, function (i, item) {
            options += '<option value="' + item.distID + '" title="' + item.name.toLowerCase() + ' (' + item.distID + ')" >' + item.name.toLowerCase() + ' (' + item.distID + ')</option>';
        });

        $('#fromList').find('option')
            .remove()
            .end();

        $('#fromList').append(options);
    })
    .success(function () { $('.modal').remove(); })
    .error(function () { 
        alert("There was an error while trying to make this request;  If it persists please contact support"); 
        $('.modal').remove(); 
     });
 }

唯一真正的区别是json.downline它可以是4种不同的东西。我添加了type参数。我试图用它来传递downline, sponsor, pSponsor or monitorlist

但我似乎只是json.typejson. + type知道我错过了什么?

1 个答案:

答案 0 :(得分:1)

json[type]将获取type命名的属性。

相关问题