fastadmin 后台给 js searchList 值返回数据

修改缘由:如果一个JS某个字段的searchList要经常变化,那要修改很多地方。

修改方案:改成后台只需要添加一次即可。

application/common/model/Website/Website.php 模型文件:

public function getCountryList()
{
    return ['0' => __('Country 0'), '1' => __('Country 1'), '2' => __('Country 2'), '3' => __('Country 3'), '4' => __('Country 4'), '5' => __('Country 5'), '6' => __('Country 6'), '7' => __('Country 7'), '8' => __('Country 8'), '9' => __('Country 9')];
}

application/lang/zh-cn/website.php 翻译文件:

<?php

return [
    'Id'         => 'ID',
    'Name'       => '名称',
    'Url'        => '域名',
    'Avatar'     => '头像',
    'Resource'   => '来源',
    'Remarks'    => '备注',
    'Status'     => '状态',
    'Status 0'   => '隐藏',
    'Status 1'   => '显示',
    'Createtime' => '添加时间',
    'Updatetime' => '更新时间',
    'Deletetime' => '删除时间',
    'Country'    => '所属国家',
    'Country 0'  => '未归类',
    'Country 1'  => '越南',
    'Country 2'  => '印尼',
    'Country 3'  => '泰国',
    'Country 4'  => '墨西哥',
    'Country 5'  => '埃及',
    'Country 6'  => '印度',
    'Country 7'  => '巴西',
    'Country 8'  => '中国',
    'Country 9'  => '美国',
];

application/admin/controller/Website.php 控制器文件:

public function _initialize()
{
    parent::_initialize();
    $this->model = new \app\common\model\Website;
    $this->view->assign("countryList", $this->model->getCountryList());
}

application/admin/view/website/index.html HTML文件:

<script> var countryList=<?php echo json_encode($countryList); ?>; </script>

public/assets/js/backend/website.js JS文件:

{field: 'country', title: __('Country'), searchList: countryList, formatter: Table.api.formatter.normal},

完成。

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值