然而,看起来它根本不起作用.我试图调试应用程序,看起来像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”]