0
<template>
<div single-value-attrib="${color}"></div>
<div single-value-attrib.bind="color"></div>
<input type="text" value.bind="color" />
</template>
視圖模型
export class SingleValueAttribCustomAttribute {
static inject = [Element];
color = 'orange';
constructor(element) {
this.element = element;
this.element.style.width = this.element.style.height = '100px';
}
bind() {
this.element.style.backgroundColor = this.value;
}
valueChanged(newValue, oldValue) {
this.element.style.backgroundColor = newValue;
}
}
我期待的是color='orange';
在視圖模型將映射到顏色上的觀點從而將默認顏色設置爲橙色。更改輸入框中的顏色按預期工作。我知道你可以設置this.value
爲默認顏色,但我只是認爲綁定的工作方式與skeleton-nav中的輸入框具有firstName和lastName的默認值相同。
將顏色更改爲值='橙色'不起作用。在構造函數中設置this.value ='orange'也不起作用,但它應該是合理的。如果我將this.value更改爲this.myvalue並將this.myvalue設置爲'orange',那麼它就可以工作。 – dan
你知道嗎?你是對的。我要更新答案是正確的。 :-) –
完美的作品,謝謝 – dan