jQuery (or any web tool) Nested Expression Builder

2019-02-01 11:08发布

问题:

I would like to add a feature to a web app I am developing to allow the user to create rules with an expression builder. Such as the one used in Magento (picture in link below).

http://i.stack.imgur.com/ZWgcG.png

I want to allows them to be able to create the expressions or if statements using column names from a table in a Database, then be able to do comparisons and what not. The expression built in the user interface would then evaluate to code that would be evaluated by a PHP script or Javascript or Perl

I searched the web for things like this that are javascript (ajax) based. I figures there has to be a module or something out on the internet somewhere for jQuery or something similar, but I haven't been able to find anything. I am also not quite sure what something like this is called besides "Expression Builder". If there is something like this out there it would save me a lot of time compared to writing it from scratch.

回答1:

In Mac OS X terms it is called a “predicate editor”, and can be found in Mail.app and iTunes. I had need for one a while ago, and scoured the web from end to end without finding one. I ended up building my own using jQuery, and it looks like this (text is in norwegian, sorry):

Sadly this is used in an internal project and the source code is not available as it is very application-specific. There is a need for a free component like this though, so if I get around to it I will try to clean this up and release it.



回答2:

This here should be exactly what you're looking for?

  • Demo: https://github.com/chrisjpowers/business-rules
  • Code: https://github.com/chrisjpowers/business-rules


回答3:

https://packagist.org/packages/ruler/ruler

https://github.com/bobthecow/Ruler

This is very similar to magento one and we are going to use it in our laravel application.more guidance for implementation you can find there.



回答4:

This fits the bill: (jquery) predicate-builder



回答5:

No mainstream tool out there for PHP... except the ones we make for ourselves :)...Its easy to implement a decent one... Just need to decide where you will store the rules... I had built one for myself with the Rule definition stored in XML ... Then updated it a few months back to store that in JSON .... You write "smarty like" templates for the output you want... 2 cases where I used this was for an Active Record implementation as well as PDF generation ... the move to JSON was because most of the newer usage scenarios were related to throwing out javascript for the pages to consume...