typehead yii2
-
Use typehead in yii2. Here's the code.
echo Typeahead::widget([ 'name' => 'search', 'value'=>(Yii::$app->request->get('search') ? Yii::$app->request->get('search') : ''), 'options' => ['placeholder' => 'Поиск'], 'pluginOptions' => ['highlight' => true], 'dataset' => [ [ 'datumTokenizer' => "Bloodhound.tokenizers.obj.whitespace('value')", 'display' => 'value', 'remote' => [ 'url' => Url::to(['/site/country-list']) . '?q=%QUERY', 'wildcard' => '%QUERY' ] ] ] ]);
The answer is returned to Json and everything is displayed, but the double quotes are screened and shown as " u o t e; Is there any way out?
-
It's not a double quote. Maybe you do it when you're preparing the server's answer? Show me the answer to the browser through the xhr.
Make the temple look like
public function actionCountryList($q) { return json_encode([['value' => 'aaa'], ['value' => '"bbb"']]); }
And look what's coming back. Don't forget to add 'cache' = false in remote.