在 jquery 插件设置中访问 aurelia 服务

Accessing an aurelia service inside of a jquery plugin's setup

正如我的问题所示,我是 ES6、Typscript 和 Aurelia 的新手。

我有一个小的 aurelia 应用程序,我想将 selectizejs 用于标记功能,但将其绑定到我在应用程序中设置的服务。

我的viewmodel.ts

    attached(){
    $('#product_tags').selectize({
        delimiter: ',',
        persist: false,
        load: function(query, callback) {
            if (!query.length) return callback();
            debugger
            this.productService.getProductTags().then(response=>{
                callback(response);
            });
        },
        create: function(input) {
            return {
                value: input,
                text: input
            }
        }
    });
}

load:function(......

如果我在函数内放置断点,我如何获得对我的服务 this.productService 的访问权限,this. 不是我的视图模型而是选择插件。

我一定是遗漏了一些明显的东西,但我想不通。

使用 es6 arrow function => 获得正确的 this

load: (query, callback) => {
        if (!query.length) return callback();
        debugger
        this.productService.getProductTags().then(response=>{
            callback(response);
        });
    },