从 AJAX 调用筛选选择



我想做的是,我想在Selection中显示accType=Acc1下注册的选择。AccInfo函数是我的 ajax 调用。我想在data中传递参数。Acc_response函数是操作期权值的函数。我想展示在Acc1下注册的branchCodeaccTypeCode。我该怎么做?

function AccInfo(Acc1){
    $.ajax({
        type:"POST",
        datatype:"json",
        async:true,
        data:{A:Acc1},
        url:AccInfo_url,
        success: function(data){
            Acc_response(data);
        },
        error: function(jqXHR, textStatus){
            errorHandling(textStatus);
        }
    })
}
function Acc_response(data){
    console.log(data);
    for (var i=0;i<data.ClientInfo.length;i++)
    {
        var $option=$('<option />');
        $option.attr('value', data.ClientInfo[i].branchCode+"|"+data.ClientInfo[i].Code+"|"+data.ClientInfo[i].accType);
        $option.text(data.ClientInfo[i].accType+" (" + data.ClientInfo[i].Code+"-"+data.ClientInfo[i].branchCode+") ";
        $('#Selection').append($option);
    }
}

这更有用;

        var selectedAccType = 'your account type';
        //you can set this at post action to
        function Acc_response(data){
              data.ClientInfo.forEach(function(client) {
                if(client.accType==selectedAccType){
                    var optionValue = client.branchCode+'|'+client.Code+'|'+client.accType;
                    var optionText = client.accType+'('client.Code+'-'+client.branchCode+')';
                    var option = '<option value="'+optionValue+'">'+optionText+'</option>';
                    $('#Selection').append(option);
                }
              });
            }

这适用于如果您有一个<select>。如果您有更多选择,请将您的 html 代码发送给我们。

最新更新