select2 下拉搜索 [ 2.0 版本 ]
Ajax搜索这边出了点问题.希望大神帮助一下
echo Select2::widget([
'name' => 'putaway_time',
'data' => $data,
'options' => ['multiple' => false, 'placeholder' => '请选择...'],
'pluginOptions' => [
'allowClear' => true,
'language' => [
'errorLoading' => new JsExpression("function () { return 'Waiting...'; }"),
],
'ajax' => [
'url' => Url::to(['book/search']),
'dataType' => 'json',
'data' => new JsExpression('function(params) { return {putaway_time:params.term}; }')
],
'escapeMarkup' => new JsExpression('function (markup) { return markup; }'),
'templateResult' => new JsExpression('function(res) { return res.text; }'),
'templateSelection' => new JsExpression('function (res) { return res.text; }'),
],
]);
Controller
public function actionSearch($putaway_time = null)
{
\Yii::$app->response->format = Response::FORMAT_JSON;
$out = ['results' => ['book_id' => '', 'putaway_time' => '']];
if (!is_null($putaway_time)) {
$data = EditorPickContent::find()
->select('book_id, putaway_time as text')
->andFilterWhere(['like', 'putaway_time', $putaway_time])
->limit(15)
->asArray()
->all();
}
$out['results'] = array_values($data);
return $out;
}
共 2 个回答
飒雅 北京
注册时间:2016-06-12
最后登录:2019-02-25
在线时长:11小时38分
最后登录:2019-02-25
在线时长:11小时38分
- 粉丝6
- 金钱5
- 威望0
- 积分115