DOJO Filtering select RegExp query

2019-08-03 09:16发布

问题:

I would like to achieve something like this:

filteringSelect.query = {id: "12|13"};

or

filteringSelect.query = {id: new RegExp("12|13")};

Is it possible?

I am using ItemFileReadStore as a store for that FilteringSelect.

回答1:

See Fuzzy Matches on dijit.form.ComboBox / dijit.form.FilteringSelect Subclass if you want to go the extra mile. This is however for filtering user-input.

For filtering away entries before opening/entering anything in the filteringSelect, continue what youre doing allready. A simple string will not accept the OR operator though, use RegExp.

ItemFileReadStore docs on query

var store = new ItemFileReadStore( {
    query: {
       id: new RegExp("/^(12|13)$/")
    }
} );

As a starting point, ALL items are present in the store, the way to make use of the queryengine is through fetch

store.fetch({
        query: { 
          // yes, you can set the query property directly 
          // in the store and leave out this parameter
            id: new RegExp("^(1|12)$")
        },
        onComplete: function(items) {
            dojo.forEach(items, function(item) {
                console.log(store.getValue(item, 'name'))
            });
        }

    })

See http://jsfiddle.net/LuUbT/ for example usage