简体   繁体   English

Aurelia oneTime绑定为defaultBindingMode

[英]Aurelia oneTime binding as defaultBindingMode

I am trying to do something like this: 我正在尝试做这样的事情:

bindable({defaultBindingMode: bindingMode.oneTime}) options = {};

and getting a warning in the browser's console: 并在浏览器的控制台中得到警告:

WARN [templating-binding] Unknown binding command. Object {defaultBindingMode: 1, attrName: "route-href", attrValue: "navModel.config.name", command: "onetime", expression: null}

Shouldn't I be able to specify that the options parameter (which is really only used once in attached() ) should only be bound one time by default? 我是否应该不能指定options参数(实际上在attached()仅使用一次)应该默认绑定一次?

You can't use the inline syntax of bindable in the way you're attempting. 您不能以尝试的方式使用可绑定的内联语法。 You need to use the more verbose syntax and decorate the class. 您需要使用更详细的语法并装饰该类。

@bindable({
    name: 'options',
    defaultBindingMode: bindingMode.oneTime,
    defaultValue: {}
});
export class MyViewModel {
...
}

The syntax for @bindable is as follows (right from the documentation): @bindable的语法如下(直接来自文档):

@bindable({
  name:'myProperty',
  attribute:'my-property',
  changeHandler:'myPropertyChanged',
  defaultBindingMode: bindingMode.oneWay,
  defaultValue: undefined
})

You have to use it this way; 您必须以这种方式使用它;

import {bindable} from 'aurelia-framework'
import {bindingMode} from 'aurelia-binding'

@bindable({name:'foo', defaultBindingMode : bindingMode.oneTime})
export class Elem{
  foo;
}

Or you can do it in-line: 或者您可以在线进行:

import {bindable} from 'aurelia-framework'
import {bindingMode} from 'aurelia-binding'

export class Elem{
  @bindable({name:'foo', defaultBindingMode : bindingMode.twoWay}) foo;
}

Here is a plunker with the code that should work. 这是一个 可以正常工作的代码。 But there is a bug at this, oneTime is ignored when used as a defaultBindingMode . 但这是一个错误,当用作defaultBindingMode时, oneTime被忽略。 See this issue I have just reported. 看到我刚刚报告的这个问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM