jqueryquerybuilder:如何初始化它并设置只读参数

of1yzvn4  于 2021-09-13  发布在  Java
关注(0)|答案(0)|浏览(265)

我正在使用jquery querybuilder插件。我启动了querybuilder,然后使用sql解析器从sql设置规则。
之后,我想将querybuilder设置为只读,这意味着querybuilder将被禁用。您将无法添加其他规则或更改当前规则。
根据文档,它应该是这样的,但无法使其工作。

$('#queryBuilder').queryBuilder('setRulesFromSQL', { flags: {
    filter_readonly: true,
    operator_readonly: true,
    value_readonly: true,
    no_delete: true },
  rules: ["name in ('Alex','Adam')"] });

有什么建议吗?我做错了什么?非常感谢你。

$(document).ready(function() { 

$('#queryBuilder').queryBuilder({
    filters: [ 
     { id: 'name',
    label: 'Name',
    type: 'string',
    value_separator: ',',
    operators: ['in']
    }
    ]
 });   

// here I set the rule from sql query without ready only feature and it works fine
$('#queryBuilder').queryBuilder('setRulesFromSQL', "name in ('Alex','Adam')");

//Here I want to update the previous method to include read only feature. 
//There will be only that rule and you can't change it. 
//I couldn't make it work although I believe I did write the correct syntax

$('#queryBuilder').queryBuilder('setRulesFromSQL',  { flags: {
    filter_readonly: true,
    operator_readonly: true,
    value_readonly: true,
    no_delete: true },
    rules: ["name in ('Alex','Adam')"]
    });

});
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<link rel='stylesheet' href="https://cdn.jsdelivr.net/npm/jQuery-QueryBuilder@2.5.2/dist/css/query-builder.default.min.css">

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jQuery-QueryBuilder@2.5.2/dist/js/query-builder.standalone.min.js"></script>
<script src="https://querybuilder.js.org/node_modules/sql-parser-mistic/browser/sql-parser.min.js"></script>

<div id="queryBuilder"></div>

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题