JavaScript中的规则引擎 [英] Rule Engine in JavaScript
问题描述
JavaScript中是否有任何规则引擎?
Is there any Rule engine in JavaScript?
问题出在这样的背景下:
The question is in this context:
- 考虑一个拥有用户填写的表单。
- 当用户填写每个字段并继续下一个字段时,用JavaScript编写的业务逻辑控制表单元素在页面下方的可见性(和其他属性) 。
-
在表单提交后,服务器端也会应用相同的业务逻辑,尽管是在Java中,以防止在浏览器端发生任何意外/操作。
- Consider a web application having a form that users fill up.
- As a user fills up each field and proceeds to the next, business logic written in JavaScript controls the visibility(and other attributes) of form elements further down the page.
The same business logic is also applied at the server side after the form gets submitted, albeit, in Java to guard against any mishaps/manipulations at the browser side.
现在,如果我们有一个JSR 94 / Drools / JRules规则引擎可以在Java和JavaScript中执行规则,那会不会很好?有了这样的规则引擎,我可以避免硬编码我的规则,并且我还保留了客户端和服务器端验证的灵活性
Now, Wouldn't it be nice if we have a JSR 94/Drools/JRules like rule engine that would execute rules in both Java and in JavaScript? With such a rule engine, I can avoid hard coding my rules, and I also retain the flexibility of having client-side as well as server-side validation
(PS:我已经尝试过AJAX路线并且看到应用程序响应速度慢很多,因此难以向习惯于手动编码,纯粹的用户销售javascript版本。)
(PS: I've tried the AJAX route and seen that the application becomes a lot less responsive, making it hard to sell to users who've been accustomed to a hand-coded, pure-javascript version.)
推荐答案
JSR-94是一个Java规范,所以我看不出它与它有什么关系浏览器。
JSR-94 is a Java specification, so I don't see what it has to do with the browser.
有Google JSON规则:
There's Google JSON rules:
http://code.google.com/p/jsonrules/
你说你试过AJAX路线。这是指在服务器上运行的规则引擎和用于访问它的异步调用吗?
You said you tried the AJAX route. Does that mean a rules engine running on the server and an asynch call to access it?
这篇关于JavaScript中的规则引擎的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!