javascript – Aurelia customAttribute无效

前端之家收集整理的这篇文章主要介绍了javascript – Aurelia customAttribute无效前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有customAttribute的问题.我想用它来插入 jquery-ui datepicker.从这里获取的想法: http://www.danyow.net/jquery-ui-datepicker-with-aurelia/

然而,看起来它根本不起作用.我试图调试应用程序,看起来像attach@datePicker.js根本没有被解雇.但是,正在从服务器请求文件本身.最糟糕的是我昨天晚上工作了,但今天早上……

我在我的骨架应用程序的分支中创建了一个简单的例子:https://github.com/Exsilium122/skeleton-navigation
所以它已准备好克隆并运行以进行故障排除.

最重要的两个文件

welcome.html

<template>
  <require from="./resources/datepicker"></require>
  <input id="myDate" datepicker="datepicker" value.bind="timestamp | dateFormat"/>
</template>

datepicker.js

import {inject,customAttribute} from 'aurelia-framework';
import 'jquery-ui';
import 'jquery-ui/themes/cupertino/jquery-ui.css!';

@customAttribute('datepicker')
@inject(Element)
export class Datepicker {
    constructor(element) {
        this.element = element;
    }

    attached = () => {
        console.log("attached Datepicker");
        $(this.element).datepicker({
            dateFormat: 'mm/dd/yy'
        }).on('change',e => fireEvent(e.target,'input'));

    }

    detached = () => {
        console.log("detached Datepicker");
        $(this.element).datepicker('destroy').off('change');
    }
}

function createEvent(name) {
    var event = document.createEvent('Event');
    event.initEvent(name,true,true);
    return event;
}

function fireEvent(element,name) {
    var event = createEvent(name);
    element.dispatchEvent(event);
}

并且控制台很干净:

DEBUG [aurelia] Loading plugin 07002.
aurelia-logging-console.js:38 DEBUG [aurelia] Configured plugin 07002.
aurelia-logging-console.js:38 DEBUG [aurelia] Loading plugin 07004.
aurelia-logging-console.js:38 DEBUG [aurelia] Configured plugin 07004.
aurelia-logging-console.js:38 DEBUG [aurelia] Loading plugin 07006.
aurelia-logging-console.js:38 DEBUG [aurelia] Configured plugin 07006.
aurelia-logging-console.js:38 DEBUG [aurelia] Loading plugin 07008.
aurelia-logging-console.js:38 DEBUG [aurelia] Configured plugin 07008.
aurelia-logging-console.js:38 DEBUG [aurelia] Loading plugin 070010.
aurelia-logging-console.js:38 DEBUG [aurelia] Configured plugin 070010.
aurelia-logging-console.js:38 DEBUG [aurelia] Loading plugin resources/index.
aurelia-logging-console.js:38 DEBUG [aurelia] Configured plugin resources/index.
aurelia-logging-console.js:46 INFO [aurelia] Aurelia Started
aurelia-logging-console.js:38 DEBUG [templating] importing resources for 070012 [“nav-bar.html”,“bootstrap/css/bootstrap.css”]
aurelia-logging-console.js:38 DEBUG [templating] importing resources for 070013 []
aurelia-logging-console.js:38 DEBUG [templating] importing resources for 070014 [“070015”]

解决方法

attached =()=> {需要更改为附加(){,如在gitter中所讨论的那样.

分离方法需要相应的变化.

这个问题可以被关闭 – OP在aurelia gitter中解决了问题.

原文链接:https://www.f2er.com/js/151373.html

猜你在找的JavaScript相关文章