Events Kartik Yii2 Typeahead小部件事件侦听器不工作

Events Kartik Yii2 Typeahead小部件事件侦听器不工作,events,yii2,twitter-typeahead,Events,Yii2,Twitter Typeahead,我的视图中有一个Kartik Yii2 typeahead小部件: echo \kartik\typeahead\Typeahead::widget([ 'name' => 'serial_product', 'options' => [ 'placeholder' => 'Product Name / SKU / Serial Number / Coupon Code', 'autofocus' => "autofocus

我的视图中有一个Kartik Yii2 typeahead小部件:

echo \kartik\typeahead\Typeahead::widget([
    'name' => 'serial_product',
    'options' => [
        'placeholder' => 'Product Name / SKU / Serial Number / Coupon Code',
        'autofocus' => "autofocus",
        'id' => 'serial_product'
    ],
    'scrollable' => TRUE,
    'pluginOptions' => [
        'highlight' => TRUE,
        'minLength' => 3
    ],
    'dataset' => [
        [
            'remote' => [
                'ttl' => 0,
                'url' => Url::to(['invoice/ajaxgetinventoryitemsnew']) . '?search=%QUERY',
                'ajax' => ['complete' => new \yii\web\JsExpression("function(response){jQuery('#serial_product').removeClass('loading');checkresult(response.responseText);return true}")]
            ],
            'limit' => 10
        ]
    ],
    'pluginEvents' => [
        "typeahead:selected" => "function(obj, item) { checkresult2(item); return true; }",
        "typeahead:render" => "function() { console.log('Whatever...'); }",
    ],
]);
第一个“pluginEvents”(typeahead:selected)被触发。 第二个“typeahead:render”未触发,并且控制台上没有错误

为什么未触发渲染事件


版本:typeahead.js 0.10.5 | Kartik typeahead.php 1.0.0

可能:使用Kartik\widgets\typeahead

$data = [
    'Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorado', 
    'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii',
    'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana'
];

// Usage with ActiveForm and model (with search term highlighting)
echo \$form->field(\$model, 'state_3')->widget(Typeahead::classname(), [
    'options' => ['placeholder' => 'Filter as you type ...'],
    'pluginOptions' => ['highlight'=>true],
    'dataset' => [
        [
            'local' => $data,
            'limit' => 10
        ]
    ]
]);

我已经在我的项目中测试了你的代码

use kartik\typeahead\Typeahead;

<?= $form->field($model, 'country')->widget(Typeahead::classname(), [
    'pluginOptions' => ['highlight' => true],
    'options' => [
        'placeholder' => 'Начните ввод страны'
    ],
    'dataset' => [
        [
            'local' => $countries,
            'limit' => 10
        ]
    ],
    'pluginEvents' => [
        "typeahead:selected" => "function(obj, item) { 
            console.log(item); return true; }",
        "typeahead:render" => "function() { 
            console.log('Whatever...'); }",
    ],
    ]);  
?>
使用kartik\typeahead\typeahead;