以下代码抛出没有错误,但它完全无效,分别是冗余的。 JQuery什么都没过滤!任何想法如何解决这一问题? 这是代码:
[
'attribute' => 'name',
'label' => 'Land',
'value' => function($model) {
if ($model->name) {
return $model->name;
} else {
return NULL;
}
},
'filterType' => GridView::FILTER_TYPEAHEAD,
'filterWidgetOptions' => [
'pluginOptions' => ['highlight' => true],
//'dataset' => [['local' => array_values(\app\models\Country::find()->orderBy('name')->asArray()->one())]
'dataset' => [['local' => array_values(ArrayHelper::map(\app\models\Country::find()->all(), 'id', 'name'))]
]],
'filterInputOptions' => ['placeholder' => 'JQuery will filter...'],
'format' => 'raw'
],

这是
的var_dump $ausgabe_ = array(array_values(ArrayHelper::map(\app\models\Country::find()->all(), 'id', 'name')));
E:\xampp\htdocs\Yii-WSL\views\country\index.php:145:
array (size=1)
0 =>
array (size=25)
0 => string 'Arabische Emirate' (length=17)
1 => string 'Algerien' (length=8)
2 => string 'Australia' (length=9)
3 => string 'Belgien' (length=7)
4 => string 'Brasilien' (length=9)
5 => string 'Canada' (length=6)
6 => string 'Schweiz' (length=7)
7 => string 'China' (length=5)
8 => string 'Zypern' (length=6)
9 => string 'Germany' (length=7)
10 => string 'Westsahara' (length=10)
11 => string 'France' (length=6)
12 => string 'United Kingdom' (length=14)
13 => string 'Ungarn' (length=6)
14 => string 'India' (length=5)
15 => string 'Laos' (length=4)
16 => string 'Russia' (length=6)
17 => string 'Sudan' (length=5)
18 => string 'Turkmenistan' (length=12)
19 => string 'Ukraine' (length=7)
20 => string 'Uganda' (length=6)
21 => string 'United States' (length=13)
22 => string 'Vatikanstadt' (length=12)
23 => string 'Vietnam' (length=7)
24 => string 'Südafrika' (length=10)

任何进一步的想法,如何解决这个问题? P.S。:如果我这样试试.....:
'dataset' => [
['local' => array_values([ArrayHelper::map(\app\models\Country::find()->orderBy('name')->asArray()->all(), 'id', 'name ')])],
]
....
的结果 $ausgabe_ = array(array_values(ArrayHelper::map(Country::find()->orderBy('name')->asArray()->all(), 'id', 'name ')));
var_dump($ausgabe_);
是这样的:
E:\xampp\htdocs\Yii-WSL\views\country\index.php:146:
array (size=1)
0 =>
array (size=25)
0 => null
1 => null
2 => null
3 => null
4 => null
5 => null
6 => null
7 => null
8 => null
9 => null
10 => null
11 => null
12 => null
13 => null
14 => null
15 => null
16 => null
17 => null
18 => null
19 => null
20 => null
21 => null
22 => null
23 => null
24 => null

答案 0 :(得分:1)
值得注意的是,数组必须带有integer
类型索引,并且不能缺少数字(索引)(例如, 0; 1; 2; 3 很好但是 0; 1; 3; 4 不是因为缺少索引2
。
唯一有效的结构(例如):
array(4) {
[0]=>
string(5) "Alpha"
[1]=>
string(4) "Beta"
[2]=>
string(5) "Gamma"
[3]=>
string(5) "Delta"
}
您的数组无效:
null
值不被接受。如果您使用array_values
:
'dataset' => [
['local' => array_values([ArrayHelper::map(\app\models\Country::find()->orderBy('name')->asArray()->all(), 'id', 'name ')])],
],