在Breeze.js实体上进行淘汰赛验证
我试图在我的Breeze.js实体上运行敲除验证,但运气不佳.
I'm trying to get Knockout Validation running on my Breeze.js entities but not having much luck.
因此,目前我只是在尝试进行一个非常基本的测试,以确认该方法是否有效,但是对于为什么这种方法不起作用感到困惑.基本上,当用户编辑我的一个实体以尝试从微风中对生成的实体进行敲除验证时,我会运行类似以下内容的东西:
So currently I'm just trying to get a very basic test working to confirm the approach should work but am stumped as to why this is not even working. Essentially I have something like the following running when the user edits one of my entities in an attempt to register knockout validation on the resulting entity from breeze:
dataService.getEntity(selectedRowId())
.then(function(result) {
currentEntity(result.entity);
var ent = currentEntity();
ent.TestField.extend({ required: true });
});
然后在视图中绑定该字段:
And then in the view the field is bound:
<input type="text" data-bind="value: currentEntity().TestField" />
但是这不起作用.我以为可能是因为实体上的所有字段都是DependantObservables,但是创建了一个测试计算字段,并且敲除验证似乎可以很好地工作(前提是我提供了读写方法)
But this is not working. I thought it might be because all the fields on the entity are dependantObservables, but created a test computed field and knockout validation seems to work fine on it (provided I give it a read and write method)
有人可以建议我可能会缺少的东西,或者是做这种事情的更好方法吗?
Can anybody suggest what I might be missing or a better way to do this sort of thing?
(PS:我实际上是在尝试类似JuliánYuste的方法:
(PS: I'm actually attempting something like the approach from Julián Yuste here:
但运气不佳,所以我试图将其归结为一些基本知识)
but not having much luck so I'm trying to take it back to some basics)
您可以在此处获得更好和更新的示例:
You can get a better and updated example here:
看看并告诉我是否有帮助.
Take a look and tell me if that helps.