Aurelia验证规则:无法解析访问器功能 [英] Aurelia Validation Rules: Unable to parse accessor function

查看:59
本文介绍了Aurelia验证规则:无法解析访问器功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于aurelia-validation模块,似乎在其他地方存在各种问题,但是我还没有发现任何能够解决我所遇到的特定问题的东西.

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;
                    }
...

这个问题是我能最接近我的问题的,而<一个href ="https://github.com/aurelia/validation/issues/341" rel ="noreferrer">这里的另一个似乎也有相同的问题.

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

我正在运行aurelia-framework@^1.0.2aurelia-validation@^1.0.0-beta.1.0.1,我认为它们只是常规更新的默认值(也是突然不起作用的原因).我是否仍在运行某些模块的不兼容版本?还是我的代码中其他地方需要修复?

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?

推荐答案

如果您以属性而不是对象为目标怎么办?这样行吗?

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

这篇关于Aurelia验证规则:无法解析访问器功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆