0

我正在尝试使用 querybuilder.js 构建一个页面,我将在其中构建一个表达式并将其转换为 JSON 规则。

下面是我的 app.js 文件

var valuesJson = [
                        {'operand1': 'operand1'},
                        {'operand2': 'operand2'},
                        {'operand3': 'operand3'}
                    ];
                    
                    
    var options = {
        allow_empty: false,
        
        operators: $.fn.queryBuilder.constructor.DEFAULTS.operators.concat([
        { type: '=', optgroup: 'custom', nb_inputs: 1, multiple: false, apply_to: ['number', 'string'] },
        { type: '!=', optgroup: 'custom', nb_inputs: 2, multiple: false, apply_to: ['number', 'string'] },
        { type: '>', optgroup: 'custom', nb_inputs: 3, multiple: false, apply_to: ['number', 'string'] },
        { type: '<', optgroup: 'custom', nb_inputs: 1, multiple: false, apply_to: ['number', 'string'] },
        { type: '>=', optgroup: 'custom', nb_inputs: 1, multiple: false, apply_to: ['number', 'string'] },
        { type: '<=', optgroup: 'custom', nb_inputs: 1, multiple: false, apply_to: ['number', 'string'] },
        { type: 'contains', optgroup: 'custom', nb_inputs: 1, multiple: false, apply_to: ['string'] },
        { type: 'begins_with', optgroup: 'custom', nb_inputs: 1, multiple: false, apply_to: ['string'] },
        { type: 'ends with', optgroup: 'custom', nb_inputs: 1, multiple: false, apply_to: ['string'] },
        { type: 'before', optgroup: 'custom', nb_inputs: 1, multiple: false, apply_to: ['string'] },
        { type: 'after', optgroup: 'custom', nb_inputs: 1, multiple: false, apply_to: ['string'] },
        { type: 'between', optgroup: 'custom', nb_inputs: 1, multiple: false, apply_to: ['string'] }
    ]),
        
        filters: [
                    
            {
                id: 'operand1',
                label: 'operand1',
                icon: 'glyphicon glyphicon-globe',
                type: 'string',
                
                input: 'select',
                //optgroup: 'core',
                //placeholder: 'Select something',
                values: valuesJson,
                operators: ['equal', 'not_equal', 'is_null','=','between','before','after']
            },
            
            {
                id: 'operand2',
                label: 'operand2',
                icon: 'glyphicon glyphicon-globe',
                type: 'string',
                
                input: 'select',
                //optgroup: 'core',
                //placeholder: 'Select something',
                values: valuesJson,
                operators: ['equal', 'not_equal', 'is_null','not_between']
            }
      
        ]

    };


    $('#builder').queryBuilder(options);

    $('.parse-json').on('click', function() {
        console.log(JSON.stringify(
            $('#builder').queryBuilder('getRules'),
            undefined, 2
        ));
    });

由于between运算符已经列在全局运算符中,因此它在过滤器中出现了两次。

在此处输入图像描述

我想摆脱全局运算符并仅从我定义的列表中选择运算符名称(即使它已经存在于全局运算符中)。

4

1 回答 1

0

我已经连接了我现在删除的全局运算符。

改变了

operators: **$.fn.queryBuilder.constructor.DEFAULTS.operators.concat**([
        { type: '=', optgroup: 'custom', nb_inputs: 1, multiple: false, apply_to: ['number', 'string'] },
        { type: '!=', optgroup: 'custom', nb_inputs: 2, multiple: false, apply_to: ['number', 'string'] },
        { type: '>', optgroup: 'custom', nb_inputs: 3, multiple: false, apply_to: ['number', 'string'] },
        { type: '<', optgroup: 'custom', nb_inputs: 1, multiple: false, apply_to: ['number', 'string'] },
        { type: '>=', optgroup: 'custom', nb_inputs: 1, multiple: false, apply_to: ['number', 'string'] },
        { type: '<=', optgroup: 'custom', nb_inputs: 1, multiple: false, apply_to: ['number', 'string'] },
        { type: 'contains', optgroup: 'custom', nb_inputs: 1, multiple: false, apply_to: ['string'] },
        { type: 'begins_with', optgroup: 'custom', nb_inputs: 1, multiple: false, apply_to: ['string'] },
        { type: 'ends with', optgroup: 'custom', nb_inputs: 1, multiple: false, apply_to: ['string'] },
        { type: 'before', optgroup: 'custom', nb_inputs: 1, multiple: false, apply_to: ['string'] },
        { type: 'after', optgroup: 'custom', nb_inputs: 1, multiple: false, apply_to: ['string'] },
        { type: 'between', optgroup: 'custom', nb_inputs: 1, multiple: false, apply_to: ['string'] }
    ]),

operators: [
        { type: '=', optgroup: 'custom', nb_inputs: 1, multiple: false, apply_to: ['number', 'string'] },
        { type: '!=', optgroup: 'custom', nb_inputs: 2, multiple: false, apply_to: ['number', 'string'] },
        { type: '>', optgroup: 'custom', nb_inputs: 3, multiple: false, apply_to: ['number', 'string'] },
        { type: '<', optgroup: 'custom', nb_inputs: 1, multiple: false, apply_to: ['number', 'string'] },
        { type: '>=', optgroup: 'custom', nb_inputs: 1, multiple: false, apply_to: ['number', 'string'] },
        { type: '<=', optgroup: 'custom', nb_inputs: 1, multiple: false, apply_to: ['number', 'string'] },
        { type: 'contains', optgroup: 'custom', nb_inputs: 1, multiple: false, apply_to: ['string'] },
        { type: 'begins_with', optgroup: 'custom', nb_inputs: 1, multiple: false, apply_to: ['string'] },
        { type: 'ends with', optgroup: 'custom', nb_inputs: 1, multiple: false, apply_to: ['string'] },
        { type: 'before', optgroup: 'custom', nb_inputs: 1, multiple: false, apply_to: ['string'] },
        { type: 'after', optgroup: 'custom', nb_inputs: 1, multiple: false, apply_to: ['string'] },
        { type: 'between', optgroup: 'custom', nb_inputs: 0, multiple: false, apply_to: ['string'] }
    ],
于 2020-09-23T05:25:35.830 回答