Aurelia:Bindable property在大多数情况下不会改变,但不是全部

时间:2018-01-21 17:12:31

标签: aurelia aurelia-binding

我正在尝试设置在Aurelia上执行某些文件上传时显示的错误消息。

HTML是:

<div if.bind="fileErrorMessage !== null" class="text-center">
 <span class="validation-error">${fileErrorMessage}</span>
</div>

错误消息的代码是:

  folderError(type) {
    if (type === "folders") {
      console.log("folders");
      this.fileErrorMessage = "ABC";
      console.log(this.fileErrorMessage);
    } else if (type === "file") {
      console.log("files");
      this.fileErrorMessage =
        "DEF";
      console.log(this.fileErrorMessage);
    } else if (type === "files_already") {
      console.log("files already");
      this.fileErrorMessage =
        "GHI";
      console.log(this.fileErrorMessage);
    } else if (type === "folders_already") {
      console.log("folders already");
      this.fileErrorMessage =
        "JKL";
      console.log(this.fileErrorMessage);
    }
  }

由于某种原因,所有控制台日志都正常启动但如果我从包含它的模块外部访问folderError函数,则会触发相应的console.logs(包括正确指出“this.fileErrorMessage”的那个)但错误消息没有出现在渲染上。

1 个答案:

答案 0 :(得分:0)

我能够通过将函数转换为箭头函数来修复它。

 folderError = (type) => {
    if (type === "folders") {
      console.log("folders");
      this.fileErrorMessage = "ABC";
      console.log(this.fileErrorMessage);
    } else if (type === "file") {
      console.log("files");
      this.fileErrorMessage =
        "DEF";
      console.log(this.fileErrorMessage);
    } else if (type === "files_already") {
      console.log("files already");
      this.fileErrorMessage =
        "GHI";
      console.log(this.fileErrorMessage);
    } else if (type === "folders_already") {
      console.log("folders already");
      this.fileErrorMessage =
        "JKL";
      console.log(this.fileErrorMessage);
    }
  }