dynamic - Aurelia `@dynamicOptions` 与 `@bindable`s 混合
问题描述
我正在使用 aureliajs 进行开发。到目前为止,我正在处理一个已标记为具有动态选项的自定义属性。例如考虑以下代码:
import {dynamicOptions, inject} from 'aurelia-framework';
@dynamicOptions
@inject(Element)
export class SquareCustomAttribute {
constructor(element){
this.element = element;
}
propertyChanged(name, newValue, oldValue){
switch(name){
case 'fill':
this.element.style.backgroundColor = newValue;
break;
case 'size':
this.element.style.width = this.element.style.height = `${newValue}px`;
break;
default:
this.element.style[name] = newValue;
break;
}
}
}
现在例如考虑我想给属性填充,defaultBindingMode
twoWay,所以我会尝试@bindable
在类中添加属性。所以代码会变成这样:
import {dynamicOptions, inject} from 'aurelia-framework';
@dynamicOptions
@inject(Element)
export class SquareCustomAttribute {
@bindable fill;
constructor(element){
this.element = element;
}
propertyChanged(name, newValue, oldValue){
switch(name){
case 'fill':
this.element.style.backgroundColor = newValue;
break;
case 'size':
this.element.style.width = this.element.style.height = `${newValue}px`;
break;
default:
this.element.style[name] = newValue;
break;
}
}
}
绑定停止工作。
那么,第一个问题是如何为dynamicOptions设置defaultBindingMode?
还有一个小问题。正如aurelia.io所说,
Binding to a dynamic options attribute works exactly the same as binding to an options attribute in the DOM.
. 根据这句话,我希望绑定动态选项破折号并检索 in camel case onoptionsChanged
方法。但是破折号分隔选项从视图中绑定,接收破折号分隔和骆驼,骆驼。根据aurelia.io的引用句子,这是正确的吗?
解决方案
感谢@bigopon,这个问题正在这个问题中得到跟进,我认为在对 aurelia-framework 进行更改之前,任何额外的评论都将是有益的。
推荐阅读
- javascript - 如何在 Vue.js 中使用 v-for 运行方法?
- r - 使用 data.table 对 r 中的序列求和
- php - 当只有第一个表中的键可用时,sql 从第二个表中获取所有条目
- javascript - 尝试发布到服务并获得对监视器的响应。但无法让 Javascript 工作
- python - 多处理不输出任何东西
- reactjs - 单击按钮后 useState 计数器闪烁
- sql - 如何找到教过最多课程的人
- python - 如何旋转这个数据框?
- pandas - 如何将此 scikit-learn 部分转换为 pandas 数据框?
- html - 如何对具有相同值的 HTML 表进行分组(Javascript)