jqhph / dcat-admin

🔥 基于 Laravel 的后台系统构建工具 (Laravel Admin),使用很少的代码快速构建一个功能完善的高颜值后台系统,内置丰富的后台常用组件,开箱即用,让开发者告别冗杂的HTML代码
http://www.dcatadmin.com
MIT License
3.81k stars 680 forks source link

Update select.blade.php #2110

Open CantonBolo opened 3 months ago

CantonBolo commented 3 months ago

添加钩子,使开发者能给指定的select控件进行个性化配置

例如:在grid方法中注入代码:

admin_inject_section('admin.select-ajax.pk_project', "console.log(configs);configs = $.extend(configs, {escapeMarkup: function(e){return e}, templateSelection: function(t){return void 0!==t.description?t.text+'  <span class=\"text-gray\">'+t.description+'</span>':t.text}})");

在页面上能在实例化之前随意配置config变量:

(function () {var configs = {"allowClear":true,"placeholder":{"id":"","text":"\u9009\u62e9"}};

    console.log(configs);configs = $.extend(configs, {escapeMarkup: function(e){return e}, templateSelection: function(t){return void 0!==t.description?t.text+'  <span class="text-gray">'+t.description+'':t.text}})

        $.ajax({"url":"http:\/\/127.0.0.1:8000\/admin\/fdc\/api\/project\/get_projects"}).done(function(data) {
        $(".pk_project").select2($.extend(configs, {
            data: data,
        })).val([]).trigger("change");
    });
})();;