如果您有项目需要开发,可以联系我们
果果开发

fastadmin动态下拉(SelectPage) 自定义参数传递

作者: admin 发布时间:2025-06-10 10:17:00

如果有下面的这段代码:

<div class="form-group">
    <label class="control-label col-xs-12 col-sm-2">{:__('Category_id')}:</label>
    <div class="col-xs-12 col-sm-8">
        <input id="c-category_id" data-rule="required" min="0" data-source="category/selectpage" data-params='{"custom[type]":"ordertype","isTree":"1"}' data-order-by="weigh" class="form-control selectpage" name="row[category_id]" type="text" value="">
    </div>
</div>
<div class="form-group">
    <label class="control-label col-xs-12 col-sm-2">{:__('Project_id')}:</label>
    <div class="col-xs-12 col-sm-8">
        <input id="c-project_id" data-rule="required" data-source="project/index" class="form-control selectpage" name="row[project_id]" type="text" value="">
    </div>
</div>

下面的动态下拉,需要根据上面的值变化,传递不同的自定义参数。

传递一个值那肯定没问题,现在的问题是,如果需要传递像MySQL中的in这种查询的,例如:

select * from td_project where category_id in (3,4)

可以这样写:

add: function () {
    this.initOrdersData();
    Controller.api.bindevent();
},
edit: function () {
    this.initOrdersData();
    Controller.api.bindevent();
},
initOrdersData: function () {
    // 订单类型变化,显示不同的表单
    $("#c-project_id").data("params", function (obj) {
        let category_id = $("#c-category_id").val();
        if (3 == category_id || 4 == category_id){
            category_id = ['in','3,4'];
        }
        return {custom: {category_id: category_id}};
    });
},

重点代码:category_id = [‘in’,’3,4′];

为什么可以这么写,可以看PHP端代码

这个搞定了,像其它的like模糊查询等都没问题了。