【问题标题】:using selectize.js with Aurelia and systemjs将 selectize.js 与 Aurelia 和 systemjs 一起使用
【发布时间】:2016-03-24 15:58:04
【问题描述】:

我正在尝试将 Selectize 与 aurelia 一起使用并不断收到错误消息:

Uncaught (in promise) TypeError: $(...).selectize is not a function(...)

我通过 index.html 中的脚本标签加载了 jquery,并尝试在一个简单的组件中加载 selectize:

EventForm.html

<template>
    <div>
        <label for="eventTitle">Title</label>
        <input type="text" id="eventTitle">
    </div>
    <div>
        <label for="eventType">Sport</label>
        <select id="eventType">
            <option>Event 1</option>
            <option>Event 2</option>
            <option>Event 3</option>
        </select>
    </div>
</template>

EventForm.js

'use strict';
import 'jspm_packages/github/selectize/selectize.js@0.12.1/dist/js/standalone/selectize';

export class EventForm {
    constructor(){

    }

    attached() {
        $('#eventType').selectize({
            create: true,
            sortField: {
                field: 'text',
                direction: 'asc'
            },
            dropdownParent: 'body'
        });
    }
}

index.html

.
.
.
<script type="text/javascript" src="jspm_packages/system.js"></script>
<script type="text/javascript" src="config.js"></script>
<script type="text/javascript" src="jspm_packages/npm/jquery@2.2.1/dist/jquery.min.js"></script>
.
.
.

我感觉这与加载 systemjs 有更多关系,但我尝试在 index.html 中加载 selectize,结果相同。有人可以帮助指出我做错了什么吗?使用 jquery 2.2.1

谢谢

【问题讨论】:

    标签: jquery aurelia systemjs selectize.js


    【解决方案1】:

    关于jquery:https://stackoverflow.com/a/34772020/3436921

    关于selectize:只需检查config.js中的地图进行选择,我想你需要像import "selectize"或import "selectize.js"一样导入它

    【讨论】:

    • 一切都正确,selectize 正在加载它只是没有按预期扩展 jquery 元素原型
    • 我的示例是使用 jquery 和 jquery 插件的推荐方式,我认为你需要加载的不是独立版本,而是 /dist/js/selectize.js,当你只是 import "selectize.js" 或 import "selectize" 时加载取决于你的 jspm 包的名称
    猜你喜欢
    • 1970-01-01
    • 2016-01-30
    • 2017-03-30
    • 1970-01-01
    • 2016-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多