Aurelia oneTime binding as defaultBindingMode
Aurelia oneTime binding as defaultBindingMode
我正在尝试做这样的事情:
bindable({defaultBindingMode: bindingMode.oneTime}) options = {};
并在浏览器的控制台中收到警告:
WARN [templating-binding] Unknown binding command. Object {defaultBindingMode: 1, attrName: "route-href", attrValue: "navModel.config.name", command: "onetime", expression: null}
我不应该指定选项参数(实际上只在attached()
中使用一次)默认情况下只能绑定一次吗?
不能以尝试的方式使用 bind 的内联语法。您需要使用更详细的语法并修饰类。
@bindable({
name: 'options',
defaultBindingMode: bindingMode.oneTime,
defaultValue: {}
});
export class MyViewModel {
...
}
@bindable
的语法如下(直接来自文档):
@bindable({
name:'myProperty',
attribute:'my-property',
changeHandler:'myPropertyChanged',
defaultBindingMode: bindingMode.oneWay,
defaultValue: undefined
})
你必须这样使用它;
import {bindable} from 'aurelia-framework'
import {bindingMode} from 'aurelia-binding'
@bindable({name:'foo', defaultBindingMode : bindingMode.oneTime})
export class Elem{
foo;
}
或者您可以内联执行此操作:
import {bindable} from 'aurelia-framework'
import {bindingMode} from 'aurelia-binding'
export class Elem{
@bindable({name:'foo', defaultBindingMode : bindingMode.twoWay}) foo;
}
这是一个包含应该工作的代码的 plunker。但是这有一个错误,oneTime
用作defaultBindingMode
时会被忽略。请参阅我刚刚报告的此问题。
相关文章:
- 没有找到相关文章