Aurelia Validation Rules: Unable to parse accessor function

穿精又带淫゛_ 提交于 2019-12-12 10:45:15

问题


It seems there have been various problems elsewhere in regards to the aurelia-validation module, but I haven't seen anything that has addressed the specific problem I've been running into.

I have a model class with the definition and validation rules as below:

my-model.js

my-model = {
    "name":
        {
        "full": "",
        "short": "",
        }
    };

...

ValidationRules
    .ensure(model => model.name.full).required().minLength(5).maxLength(50)
    .on(this.my-model);

When I try it in the browser, however, I get the error:

...
Inner Error:
Message: Unable to parse accessor function:
function (model) {
                        return model.name.full;
                    }
...

This question was the closest I was able to see to my problem, and another here seems to be having the same issue.

I am running aurelia-framework@^1.0.2 and aurelia-validation@^1.0.0-beta.1.0.1 which I believe are just the defaults from regular updates (but also the reason for it suddenly not working). Is it possible I'm still running incompatible versions of some modules? Or is there somewhere elsewhere in my code that I need to fix?


回答1:


What if you target the property instead of the object? Does that work?

myModel = {
  "name": {
    "full": "",
    "short": "",
  }
};

ValidationRules
  .ensure(model => model.full)
    .required()
    .minLength(5)
    .maxLength(50)
  .on(this.myModel.name); //<--- see


来源:https://stackoverflow.com/questions/41599681/aurelia-validation-rules-unable-to-parse-accessor-function

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!