gpt4 book ai didi

javascript - Aurelia customAttribute 不工作

转载 作者:数据小太阳 更新时间:2023-10-29 05:05:30 26 4
gpt4 key购买 nike

我对 customAttribute 有疑问。我想用它来插入 jquery-ui datepicker。想法取自这里:http://www.danyow.net/jquery-ui-datepicker-with-aurelia/

但是看起来它根本不起作用。我尝试调试应用程序,看起来 attached@datePicker.js 根本没有被触发。但是,文件本身是从服务器请求的。最糟糕的是我昨天晚上让它工作,但今天早上......

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

最重要的两个文件:


欢迎.html

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

日期选择器.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 http://localhost:9000/jspm_packages/github/aurelia/templating-binding@0.16.1. aurelia-logging-console.js:38 DEBUG [aurelia] Configured plugin http://localhost:9000/jspm_packages/github/aurelia/templating-binding@0.16.1. aurelia-logging-console.js:38 DEBUG [aurelia] Loading plugin http://localhost:9000/jspm_packages/github/aurelia/templating-resources@0.16.1. aurelia-logging-console.js:38 DEBUG [aurelia] Configured plugin http://localhost:9000/jspm_packages/github/aurelia/templating-resources@0.16.1. aurelia-logging-console.js:38 DEBUG [aurelia] Loading plugin http://localhost:9000/jspm_packages/github/aurelia/history-browser@0.9.0. aurelia-logging-console.js:38 DEBUG [aurelia] Configured plugin http://localhost:9000/jspm_packages/github/aurelia/history-browser@0.9.0. aurelia-logging-console.js:38 DEBUG [aurelia] Loading plugin http://localhost:9000/jspm_packages/github/aurelia/templating-router@0.17.0. aurelia-logging-console.js:38 DEBUG [aurelia] Configured plugin http://localhost:9000/jspm_packages/github/aurelia/templating-router@0.17.0. aurelia-logging-console.js:38 DEBUG [aurelia] Loading plugin http://localhost:9000/jspm_packages/github/aurelia/event-aggregator@0.9.0. aurelia-logging-console.js:38 DEBUG [aurelia] Configured plugin http://localhost:9000/jspm_packages/github/aurelia/event-aggregator@0.9.0. 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 http://localhost:9000/dist/app.html ["nav-bar.html", "bootstrap/css/bootstrap.css"] aurelia-logging-console.js:38 DEBUG [templating] importing resources for http://localhost:9000/dist/nav-bar.html [] aurelia-logging-console.js:38 DEBUG [templating] importing resources for http://localhost:9000/dist/welcome.html ["http://localhost:9000/dist/resources/datepicker"]

最佳答案

attached = () => { 需要更改为 attached() {,如 gitter 中所述。

detached 方法需要相应的更改。

这个问题可以关闭 - OP 在 aurelia gitter 中解决了这个问题。

关于javascript - Aurelia customAttribute 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33368370/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com