jquery - How to iterate through datasource to create Querybuilder filters -


i'm new jquery/json. using mistic100's querybuilder i'm unsure how load filters data source. in example, 3 filters loaded builder. syntax-wise, how data source? guess i'm not understanding how iterate through of filters if in data source.

    $('#builder-basic').querybuilder({       plugins: ['bt-tooltip-errors'],        filters: [{         id: 'name',         label: 'name',         type: 'string'       }, {         id: 'category',         label: 'category',         type: 'integer',         input: 'select',         values: {           1: 'books',           2: 'movies',           3: 'music',           4: 'tools',           5: 'goodies',           6: 'clothes'         },         operators: ['equal', 'not_equal', 'in', 'not_in', 'is_null',     'is_not_null']       }, {         id: 'in_stock',         label: 'in stock',         type: 'integer',         input: 'radio',         values: {           1: 'yes',           0: 'no'         },         operators: ['equal']       }       }],       rules: rules_basic     }); 

thanks help.

when create filter in gui, can save filter;

var myfilter = $('#builder-basic').querybuilder('getrules'); 

you can store datastore other data. want serialize it;

var myfilterstring=""; if (!$.isemptyobject(myfilter)) {myfilterstring =json.stringify(genresult, null, 2); 

then later if need show data, can pull rule string , deserialize it, , use setrules show rule in gui.

$('#builder-basic').querybuilder('setrules', json.parse(myfilterstring)); 

if wanting set rule wasnt created using gui, need create object of required structure , use setrules - or define in string format, deserialize , use setrules.

the json looks this

var rules_widgets = {   condition: 'or',   rules: [{     id: 'date',     operator: 'equal',     value: '1991/11/17'   },     {     id: 'rate',     operator: 'equal',     value: 22   }, {     id: 'category',     operator: 'equal',     value: '38'   }, {     condition: 'and',     rules: [{       id: 'coord',       operator: 'equal',       value: 'b.3'     }]   }] }; 

Comments