@bindable的操作顺序

问题描述 投票:1回答:1

如果我有一个孩子控制(或在这种情况下是孙子),看起来像这样:

<my-control region-id.two-way="location.regionId"></my-control>

我什么时候可以期待regionId可用?文档听起来像绑定然后附加发生所以不应该在附加发生之前设置regionId

我添加了一些日志记录到bindattachedregionIdChanged事件,看着控制台,我看到了

bind
attached
regionIdChange to null from undefined (default value in a dropdown)
regionIdChange to 1 from null (1 is the actual value)

我本来期望regionIdattached发生之前是1。这是预期的行为吗?

aurelia aurelia-binding aurelia-framework
1个回答
3
投票

该变量应填入bind()阶段。

如果您将记录添加到每个阶段:

export class Child {
  @bindable()
  public field: string;

  constructor() {
    console.info("constructor: ", this.field);
  }

  bind() {
    console.info("bind: ", this.field);
  }

  attached() {
    console.info("attached: ", this.field);
  }
}

它产生以下日志输出:

constructor:  undefined
bind:  test
attached:  test

其中test是我绑定它的价值。

© www.soinside.com 2019 - 2024. All rights reserved.