在work的index中添加
<div class="panel-heading">
{:build_heading(null,FALSE)}
<ul class="nav nav-tabs" data-field="type_id">
<li class="active"><a href="#t-all" data-value="" data-toggle="tab">{:__('All')}</a></li>
{foreach name="typeIdList" item="vo"}
<li><a href="#t-{$key}" data-value="{$key}" data-toggle="tab">{$vo}</a></li>
{/foreach}
</ul>
</div>
在work的controll的_initialize方法最后一行添加
$this->view->assign("typeIdList", $this->model->getTypeIdList());
在work的model中添加
public function getTypeIdList()
{
$list = TypeModel::select();
$temp = [];
foreach($list as $k=>$vo){
$a1=array($vo['id']=>$vo['name']);
$temp = $temp+$a1;
}
return $temp;
}
最后,还要在work的js中,添加type_id的operate: 'LIKE'
{field: 'type_id', title: __('Type_id'),operate: 'LIKE',},
如果需要在work列表中,显示_id的中文
在work的controll中添加type类,重写index方法
use app\admin\model\Type as TypeModel;
public function index()
{
//设置过滤方法
$this->request->filter(['strip_tags']);
if ($this->request->isAjax())
{
//如果发送的来源是Selectpage,则转发到Selectpage
if ($this->request->request('keyField'))
{
return $this->selectpage();
}
$typeName = TypeModel::column('id,name');
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$total = $this->model
->where($where)
->order($sort, $order)
->count();
$list = $this->model
->where($where)
->order($sort, $order)
->limit($offset, $limit)
->select();
$list = collection($list)->toArray();
foreach ($list as $k => &$v)
{
$v['type_text'] = isset($typeName[$v['type_id']]) ? $typeName[$v['type_id']] : "";
}
unset($v);
$result = array("total" => $total, "rows" => $list);
return json($result);
}
return $this->view->fetch();
}
然后在对应的js中
{field: 'type_text', title: __('type_id'),operate: false,formatter: Table.api.formatter.label},