Typeahead Widget高级Yii2

时间:2015-09-21 18:33:18

标签: yii2 bootstrap-typeahead

我尝试使用此小部件从我的控制器创建实时搜索。

ActiveForm::begin([
    'action' => Url::to(['product/search']),
    'id' => 'main-search-form',
    ]) ?>

<?php //echo Html::input('text', 'search') ?>
<?php echo Typeahead::widget([
     'name' => 'search',
     'options' => ['placeholder' => 'Search...'],
     'scrollable' => true,
     'pluginOptions' => ['highlight'=>true],
     'dataset' => [
                      [
                      'remote' => [ 
                           'url' => Url::to(['product/searchlist']) . '?search=%query'
                            ],
                      'limit' => 10
                      ]
                  ]
            ]);

这是我在产品/搜索列表中的答案:

[{"product_name":"Garant"},{"product_name":"Garant"},{"product_name":"Garant"},{"product_name":"pay 8"},{"product_name":"pay 8"},{"product_name":"pay 8"},{"product_name":"pay1"},{"product_name":"pay1"},{"product_name":"pay1"},{"product_name":"pay1dd"},{"product_name":"pay1dd"},{"product_name":"pay1dd"},{"product_name":"pay1jjj fixed"},{"product_name":"pay6"},{"product_name":"pay6"},{"product_name":"pay6"}]

当我在搜索框中键入内容时,它会显示我:

{"_query":"{\"product_name\":\"Garant\"}","product_name":"Garant"}

下拉列表中的某种字段

0 个答案:

没有答案