【问题标题】:TypeError when using apostrophe with materialize将撇号与具体化一起使用时出现 TypeError
【发布时间】:2019-04-27 06:28:54
【问题描述】:

我创建了一个示例 repo 来显示我在将具体化加载到撇号资产管道时遇到的一些错误。这是作为最小示例的撇号样板,公共资产文件夹中包含 materialize.css 和 .js。

在管理界面中打开图像、文件或页面的模式时出现以下错误用户或全局不要抛出此错误:

TypeError: this.dropdownEl is null materialize.js:2571:9
    _makeDropdownFocusable http://localhost:3000/modules/my-apostrophe-assets/js/materialize.js:2571
    Dropdown http://localhost:3000/modules/my-apostrophe-assets/js/materialize.js:2299
    init http://localhost:3000/modules/my-apostrophe-assets/js/materialize.js:1045
    init http://localhost:3000/modules/my-apostrophe-assets/js/materialize.js:2825
    _setupDropdown http://localhost:3000/modules/my-apostrophe-assets/js/materialize.js:6561
    Autocomplete http://localhost:3000/modules/my-apostrophe-assets/js/materialize.js:6478
    init http://localhost:3000/modules/my-apostrophe-assets/js/materialize.js:1049
    init http://localhost:3000/modules/my-apostrophe-assets/js/materialize.js:6878
    pluginName http://localhost:3000/modules/my-apostrophe-assets/js/materialize.js:1153
    selective jQuery
    enableTags http://localhost:3000/modules/apostrophe-schemas/js/user.js:515
    populate http://localhost:3000/modules/apostrophe-schemas/js/user.js:1160
    populate http://localhost:3000/modules/apostrophe-schemas/js/user.js:42
    _withoutIndex http://localhost:3000/modules/apostrophe-assets/js/vendor/async.js:181
    iterate http://localhost:3000/modules/apostrophe-assets/js/vendor/async.js:262
    iterate http://localhost:3000/modules/apostrophe-assets/js/vendor/async.js:274
    only_once http://localhost:3000/modules/apostrophe-assets/js/vendor/async.js:44
    partiallyApplied http://localhost:3000/modules/apostrophe-assets/js/vendor/setImmediate.js:27
    runIfPresent http://localhost:3000/modules/apostrophe-assets/js/vendor/setImmediate.js:46
    onGlobalMessage http://localhost:3000/modules/apostrophe-assets/js/vendor/setImmediate.js:92

我认为这是由materialize.js中的以下功能引起的:

/**
 * Initialize jQuery wrapper for plugin
 * @param {Class} plugin  javascript class
 * @param {string} pluginName  jQuery plugin name
 * @param {string} classRef  Class reference name
 */
M.initializeJqueryWrapper = function (plugin, pluginName, classRef) {
  jQuery.fn[pluginName] = function (methodOrOptions) {
    // Call plugin method if valid method name is passed in
    if (plugin.prototype[methodOrOptions]) {
      var params = Array.prototype.slice.call(arguments, 1);

      // Getter methods
      if (methodOrOptions.slice(0, 3) === 'get') {
        var instance = this.first()[0][classRef];
        return instance[methodOrOptions].apply(instance, params);
      }

      // Void methods
      return this.each(function () {
        var instance = this[classRef];
        instance[methodOrOptions].apply(instance, params);
      });

      // Initialize plugin if options or no argument is passed in
    } else if (typeof methodOrOptions === 'object' || !methodOrOptions) {
      plugin.init(this, arguments[0]);
      return this;
    }

    // Return error if an unrecognized  method name is passed in
    jQuery.error("Method " + methodOrOptions + " does not exist on jQuery." + pluginName);
  };
};

我真的很高兴有人可以看看这个错误是如何解决的。谢了

【问题讨论】:

    标签: jquery materialize apostrophe-cms


    【解决方案1】:

    我在lib/modules/apostrophe-assets/index.js 中找到了将物化作为组件添加到撇号资产管道的最简单解决方案。如果您不使用所有组件,这甚至可以节省很多不必要的文件。

       ...
        {
          name: 'vendor/materialize/cash'
        },
        {
          name: 'vendor/materialize/component'
        },
        {
          name: 'vendor/materialize/global'
        },
       ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-17
      • 1970-01-01
      相关资源
      最近更新 更多