Aurelia `@dynamicOptions` 与 `@bindable` 混合
Aurelia `@dynamicOptions` mixed with `@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;
}
}
}
现在例如考虑我要给twoWay的属性填充,defaultBindingMode
,所以我会尝试在[=中添加@bindable
属性 33=]。所以代码会变成这样:
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 says, Binding to a dynamic options attribute works exactly the same as binding to an options attribute in the DOM.
. According to this sentence, I expect to bind dynamic options dash seperated and retrieve the in camel case on optionsChanged
method. But dash seperated options bound from view, receives dash separated and camels, camels. Is this correct according to referenced sentence from aurelia.io?
感谢@bigopon,这个问题正在 this issue 中跟进,我认为在对 aurelia-framework 进行更改之前,对此问题的任何其他评论都是有益的。
我正在使用 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;
}
}
}
现在例如考虑我要给twoWay的属性填充,defaultBindingMode
,所以我会尝试在[=中添加@bindable
属性 33=]。所以代码会变成这样:
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 says,
Binding to a dynamic options attribute works exactly the same as binding to an options attribute in the DOM.
. According to this sentence, I expect to bind dynamic options dash seperated and retrieve the in camel case onoptionsChanged
method. But dash seperated options bound from view, receives dash separated and camels, camels. Is this correct according to referenced sentence from aurelia.io?
感谢@bigopon,这个问题正在 this issue 中跟进,我认为在对 aurelia-framework 进行更改之前,对此问题的任何其他评论都是有益的。