簡體   English   中英

如何在yii2中使用handlerbars提前輸入?

[英]How to make typeahead with handlerbars in yii2?

我是yii2的初學者。 我想在我的項目中創建搜索表單。 因此,我使用帶有把手的typeahead。 但是,它沒有顯示下拉選項。 這是我的代碼:

控制器:

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}')")
                    ]
                ]
            ]
        ]);
    ?>

試試吧:

    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>')")
                ]
            ]
        ]
    ]);
?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM