【发布时间】:2017-08-23 00:30:23
【问题描述】:
是否可以在 Aurelia 中使用带有自定义属性的 vanilla js setAttribute()?当我检查 dom 时,对自定义元素进行了更改,但无论我尝试什么,它似乎都不会触发我的模型或视图中的任何内容。是否有“最佳实践”方式来做到这一点?
home.ts
export class Home{
public onButtonClicked():void{
document.getElementById('test123').setAttribute('color', 'green');
}
}
home.html
<template>
<require from="../../elements/now-loading-circle/now-loading-circle"></require>
<button click.delegate="onButtonClicked()">Click</button>
<now-loading-circle id="test123" color="red"></now-loading-circle>
</template>
now-loading-circle.ts
import {bindable, autoinject} from 'aurelia-framework';
@autoinject
export class NowLoadingCircle{
@bindable color:string;
public colorChanged(newValue):void{
alert(newValue);
}
}
现在加载-circle.html
<template>
<svg viewBox="0 0 120 120">
<circle repeat.for="circ of coords" cx="${circ.x}" cy="${circ.y}" r="${smallCircleRadius}" class="circ-${$index + 1}"></circle>
</svg>
</template>
【问题讨论】:
-
您尝试使用 setAttribute() 吗?怎么样?
-
@YoungKyunJin 是的,当我检查 dom 时,对自定义元素进行了更改,但无论我尝试什么,它似乎都不会触发我的模型或视图中的任何内容。跨度>
-
我可以看到你的代码吗?
-
@YoungKyunJin - 我用我的代码更新了这个问题。
colorChanged在页面加载时触发一次,但不再触发。按下按钮后,当我检查浏览器中的元素时,color="green"但colorChanged永远不会触发。
标签: javascript aurelia