开发者

searchAttr combobox array

I was wondering how could I have mutli-search Attr in my combobox. I would like to have someting like :

     var cb = dijit.byId('myCombo');
     cb.attr('store', store);
     cb.attr('searchAttr', ["nam开发者_运维知识库e","age"]);

So I can make autocomplete on two criterias.


I will assume you are using a dojo.data.ItemFileReadStore. The searchAttr is only for the attribute you're typing in the ComboBox.

For example, if you're typing a name, but you also want to filter by age, you add a field to the query parameter:

// Get names with age=30
// Use set because attr is deprecated
cb.set( 'query', { 'age' : 30 });

If you want to be more specific with a name when the page is initially loaded, you can specify it in your query:

// All names starting with 'a' and age=30
cb.set( 'query', { 'name' : 'a*', 'age' : 30 });

If you want your age to be dynamic, you must get it from another place (e.g. dijit, form element, dom node, etc.). Here is an example to get age from another dijit called 'anotherDijit' (a NumberTextBox for example) when the page loads:

// Get names with age specified in 'anotherDijit'
cb.set( 'query', { 'age' : dijit.byId('anotherDijit').getValue() } );

However, for the age value in the query to change when the 'anotherDijit' diijt changes, you have to do one of two things:

  1. Attach an observer/event handler to an appropriate 'anotherDijit' event (e.g. onChange), which will update the new 'anotherDijit' value in your ComboBox store query. This is a PUSH approach.
  2. Attach an observer/event handler to an appropriate ComboBox event (e.g. onFocus), which will PULL the current value from the 'anotherDijit' dijit, and then update the store query parameter.

Notice that the fields you put in 'query' parameter are queried like AND (name=this AND age=that, etc). If you need more complex queries, with ORs and NOTs, you can use dojox.data.AndOrReadStore, for example.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜