动态渲染select表单

    form.on('radio(xf_step_type)', function (data) {
        let radioVal = $('#IsPurchased input[name="processor_type"]:checked ').val();
        var param;
        if (radioVal === "member") {
            param = 'member';
        }else if(radioVal === "department"){
            param = 'department';
        }else{
            param = 'position';
        }

        //请求数据
        $.ajax({
            url:'/manage/public/select_table/' + param,
            dataType:'json',
            type:'post',
            async:false,
            headers:{"X-CSRF-TOKEN" : $('meta[name="csrf-token"]').attr('content')},
            success:function(res){
                //先清空select列表数据
                $("#processor").empty();
                $.each(res.data,function(index,item){
                    //方法一
                    $('#processor').append(new Option(item.title,item.id));
                    //方法二 往下拉菜单里添加元素
                    //$("#processor").append("<option value='"+item.id+"'>"+item.title+"</option>");
                })
                form.render();//菜单渲染 把内容加载进去
            }
        });
        //form.render();
    });

标签: none

添加新评论