最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - jQuery (or any web tool) Nested Expression Builder - Stack Overflow

programmeradmin3浏览0评论

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).

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

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).

https://i.sstatic.net/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.

Share Improve this question edited Aug 13, 2011 at 1:21 Lightness Races in Orbit 385k77 gold badges664 silver badges1.1k bronze badges asked Aug 11, 2011 at 19:37 MarcMarc 1411 silver badge3 bronze badges 4
  • Currently I have that right now, but this is meant to be for users who dont have much programming knowledge. Don't want them to have to worry about syntax errors and trying to figure out what values correspond with that variables and etc. What to make it easy for the user – Marc Commented Aug 12, 2011 at 18:51
  • 1 It seems a bit like a business rules application. Not sure if one exists. – Jared Farrish Commented Aug 13, 2011 at 1:23
  • 1 I don't think there is a ready-made component available as it's normally pretty specific and compared to that pretty easy to implement with DOM/JQuery. – hakre Commented Aug 13, 2011 at 13:19
  • @dqhendricks: Security is a huge argument against that; besides that the average user won't be able to write proper (or even any) PHP code.. – ThiefMaster Commented Aug 15, 2011 at 7:18
Add a comment  | 

5 Answers 5

Reset to default 4

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.

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

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

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.

This fits the bill: (jquery) predicate-builder

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

发布评论

评论列表(0)

  1. 暂无评论