2016-04-21 71 views
0

我是yii2的初學者。我想在我的項目中進行搜索。所以,我使用帶把手的打字頭。但是,它不顯示下拉選項。這是我的代碼:如何使用yii2中的處理欄進行預先打印?

控制器:

public function actionPrefetchlist() 
    { 
     $query = new Query; 

     $query->select('nama') 
       ->from('tb_penerima'); 
     $command = $query->createCommand(); 
     $data = $command->queryAll(); 
     $out = []; 
     foreach ($data as $d){ 
      $out[] = ['value' => $d['nama']]; 
     } 
     return Json::encode($out); 
    } 

觀點:

<?php 
     echo '<label class="control-label">Select Repository</label>'; 
     $template = '<div><p>{{nama}}</p>'; //This is not working 
     echo Typeahead::widget([ 
      'name' => 'twitter_oss', 
      'options' => ['placeholder' => 'Filter as you type ...'], 
      'dataset' => [ 
       [ 
        'prefetch' => Url::to(['paket/prefetchlist']), 
        'datumTokenizer' => "Bloodhound.tokenizers.obj.whitespace('value')", 
        'display' => 'value', 
        'templates' => [ 
         'notFound' => '<div class="text-danger" style="padding:0 8px">Unable to find repositories for selected query.</div>', 
         'suggestion' => new JsExpression("Handlebars.compile('{$template}')") 
        ] 
       ] 
      ] 
     ]); 
    ?> 
+0

(HTTP [在預輸入handlerbars的預取缺少]的可能重複: //stackoverflow.com/questions/36763443/missing-in-prefetch-of-typeahead-handlerbars) – Epodax

回答

0

試試:

echo '<label class="control-label">Select Repository</label>'; 
    echo Typeahead::widget([ 
     'name' => 'twitter_oss', 
     'options' => ['placeholder' => 'Filter as you type ...'], 
     'dataset' => [ 
      [ 
       'prefetch' => Url::to(['paket/prefetchlist']), 
       'datumTokenizer' => "Bloodhound.tokenizers.obj.whitespace('value')", 
       'display' => 'value', 
       'templates' => [ 
        'notFound' => '<div class="text-danger" style="padding:0 8px">Unable to find repositories for selected query.</div>', 
        'suggestion' => new JsExpression("Handlebars.compile('<div><p>{{value}}</p></div>')") 
       ] 
      ] 
     ] 
    ]); 
?> 
相關問題