Php Yii2 select2 optGroup不使用ajax
我试图在kartik Select2上运行ajax搜索,但我遇到了一个无法解决的问题 视图: 控制器:Php Yii2 select2 optGroup不使用ajax,php,ajax,yii2,jquery-select2,Php,Ajax,Yii2,Jquery Select2,我试图在kartik Select2上运行ajax搜索,但我遇到了一个无法解决的问题 视图: 控制器: public function actionGlobalSearch($q = null) { $Data = ['Pages' => [['id' => 'index.php', 'text' => 'Home']]]; if (!is_null($q)) { $Categories = new ActiveD
public function actionGlobalSearch($q = null) {
$Data = ['Pages' => [['id' => 'index.php', 'text' => 'Home']]];
if (!is_null($q)) {
$Categories = new ActiveDataProvider([
'query' => \app\models\CategoryOfItems::find()->innerJoin('category_of_items_trans', 'category_of_items_trans.CATEGORY_OF_ITEM_ID=category_of_items.CATEGORY_OF_ITEM_ID')->where('category_of_items_trans.CATEGORY_OF_ITEM_TRANS LIKE \'%' . $q . '%\' AND LANGUAGE_ID=1'),
// ->innerJoin('agenda_periode_translation','agenda_periode_translation.AGENDA_PERIOD_ID = AGENDA_PERIODE_ID')->andFilterWhere(['=', 'agenda_periode_translation.LANGUAGE_ID', 2]),
]);
if ($Categories != null) {
$Categories = $Categories->getModels();
$i = 0;
if ($Categories != null && sizeof($Categories) > 0) {
foreach ($Categories as $Category) {
$Data['Categories'][$i] = ['id' => 'index.php?r=category-of-items%2Findex&Reg=C&CategoryID=' . $Category->CATEGORY_OF_ITEM_ID];
$Data['Categories'][$i] = ['text' => $Category->categoryOfItemsTrans[0]->CATEGORY_OF_ITEM_TRANS];
$i++;
}
}
}
}
Yii::error(print_r($Data, true));
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
return ['results' => $Data];
}
控制器的功能可以正常工作。以下是返回的结果:
Array
(
[Pages] => Array
(
[0] => Array
(
[id] => index.php
[text] => Home
)
)
[Categories] => Array
(
[0] => Array
(
[text] => Financial Services
)
[1] => Array
(
[text] => General Services
)
[2] => Array
(
[text] => Site decoration
)
[3] => Array
(
[text] => Food & Beverage
)
[4] => Array
(
[text] => Music & Entertainment
)
[5] => Array
(
[text] => Body & Beauty Preparation
)
[6] => Array
(
[text] => Others: Dance, Souvenirs…
)
[7] => Array
(
[text] => Accommodation
)
[8] => Array
(
[text] => Transportation
)
[9] => Array
(
[text] => Trip Preparation
)
[10] => Array
(
[text] => Domestic Destinations
)
[11] => Array
(
[text] => Egypt, Mid-East, Turkey
)
[12] => Array
(
[text] => Russia, Armenia, Central Asia
)
[13] => Array
(
[text] => South & South-East Asia
)
[14] => Array
(
[text] => Eastern Asia
)
[15] => Array
(
[text] => Eastern Europe
)
[16] => Array
(
[text] => Eastern Africa
)
[17] => Array
(
[text] => Western Africa
)
[18] => Array
(
[text] => Southern Africa
)
[19] => Array
(
[text] => Northern Africa
)
)
)
但是生成的错误是javascript错误,我认为问题在于processResults选项
这是生成的错误:
select2.full.js:4008 Uncaught TypeError: data.slice is not a function
at DecoratedClass.HidePlaceholder.removePlaceholder (select2.full.js:4008)
at DecoratedClass.removePlaceholder (select2.full.js:580)
at DecoratedClass.HidePlaceholder.append (select2.full.js:3991)
at DecoratedClass.append (select2.full.js:580)
at Select2.<anonymous> (select2.full.js:1011)
at Select2.Observable.invoke (select2.full.js:637)
at Select2.Observable.trigger (select2.full.js:627)
at Select2.trigger (select2.full.js:5472)
at select2.full.js:5331
at Object.options.transport.self.trigger.message (select2.full.js:3468)
select2.full.js:4008未捕获类型错误:data.slice不是函数
在DecoratedClass.HidePlaceholder.removePlaceholder(select2.full.js:4008)中
在DecoratedClass.removePlaceholder(选择2.full.js:580)
在DecoratedClass.HidePlaceholder.append(选择2.full.js:3991)
在DecoratedClass.append(选择2.full.js:580)
在Select2。(选择2.full.js:1011)
在Select2.Observable.invoke(Select2.full.js:637)
在Select2.Observable.trigger(Select2.full.js:627)
在Select2.trigger(Select2.full.js:5472)
在select2.full.js:5331
在Object.options.transport.self.trigger.message(select2.full.js:3468)
求你了,我需要你的帮助,我找不到解决办法。
先谢谢你 结果应返回id和文本。请参考此链接:10x以获取回复。我试图做的是对结果进行分组。结果应该返回id和文本。请参考此链接:10x以获取回复。我想做的是把结果分组。
select2.full.js:4008 Uncaught TypeError: data.slice is not a function
at DecoratedClass.HidePlaceholder.removePlaceholder (select2.full.js:4008)
at DecoratedClass.removePlaceholder (select2.full.js:580)
at DecoratedClass.HidePlaceholder.append (select2.full.js:3991)
at DecoratedClass.append (select2.full.js:580)
at Select2.<anonymous> (select2.full.js:1011)
at Select2.Observable.invoke (select2.full.js:637)
at Select2.Observable.trigger (select2.full.js:627)
at Select2.trigger (select2.full.js:5472)
at select2.full.js:5331
at Object.options.transport.self.trigger.message (select2.full.js:3468)