Drupal 8中自动完成的依赖关系

时间:2016-11-03 19:18:40

标签: autocomplete drupal-8

我尝试在搜索中实现自动填充字段。声明所有依赖项后,控制台页面始终显示我的函数自动完成不存在:

PHP

$form['basic']['keys'] = array(
  '#type' => 'search',
  '#title' => $this->t('Digite sua pesquisa'),
  '#default_value' => $keys,
  '#size' => 30,
  '#maxlength' => 255,
);

$form['#attached']['library'][] = 'busca/busca_form';
$form['basic']['submit'] = array(
  '#type' => 'submit',
  '#value' => $this->t('Search'),

我的js

$(document).ready(function(){

var availableTags = [
  "ActionScript",
  "AppleScript",
  "Asp",
  "BASIC",
];


$("#edit-keys" ).autocomplete({
  source: availableTags
});

});

和我的图书馆

busca_form:
  version: VERSION
  js:
    js/complete.js: {}
  dependencies:
    - core/jquery
    - core/drupal.ajax
    - core/drupal
    - core/drupalSettings
    - core/jquery.once
    - core/jquery.ui.autocomplete

错误:complete.js?v = 8.1.2:35未捕获TypeError:$(...)。autocomplete不是函数(...)

任何想法? TKS

1 个答案:

答案 0 :(得分:0)

这样在这里工作正常。

(function ($, Drupal, drupalSettings, doc) {
    "use strict";

    Drupal.behaviors.Myautocomplete = {
        attach: function myFunc(context, settings) {
     

        
                var options = ["Java", "Jaca"];
                jQuery("#lookfor").autocomplete({
                source: options
                });
            
        
        
        },
    };
})(jQuery, Drupal, drupalSettings, document);