Typeahead不是显示选项

时间:2016-04-18 14:34:49

标签: php yii2

我的项目有些问题。我使用typeahead进行搜索。所以,我使用带把手的typeahead。但是,有一个问题,因为它不显示选项。这是我的代码:

模型:

public function getDataForJson($q = null)
    {
        if($q === null)
        {
            $penerimas = Penerima::findAll('');
            if(empty($penerimas))
            {
                return array('value' => 'No Data');
            }
            else
            {
                $u = array();
                foreach ($penerimas as $penerima)
                {
                    $u[] = ['value' => $penerima->nama];
                }
                return $u;
            }
        }
        else
        {
            $query = new Query;
            $query->select(['nama'])->from('tb_penerima');
            $data = $query->createCommand()->queryAll();
            if(empty($data))
            {
                return array('value' => 'No Data');
            }
            else
            {
                $return = [];
                foreach ($data as $datum)
                {
                    $out[] = ['value' => $datum['nama']];
                }
                return $out;
            }
        }
    }

视图:

<?php
        echo '<label class="control-label">Select Repository</label>';
        $template = '<div><p class="repo-language">{{no_telepon}}</p>' .
                    '<p class="repo-name">{{nama}}</p>';
                    '<p class="repo-description">{{email}}</p></div>';
        echo Typeahead::widget([
            'name' => 'twitter_oss',
            'options' => ['placeholder' => 'Filter as you type ...'],
            'dataset' => [
                [
                    'prefetch' => Url::to(['tertuju/getpenerima']),
                    '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}')")
                    ]
                ]
            ]
        ]);
    ?>

控制器:

public function actionGetpenerima($q = null)
    {
        return Json::encode(Tertuju::getDataForJson($q));
    }

0 个答案:

没有答案