searchAttr组合框数组 [英] searchAttr combobox array

查看:230
本文介绍了searchAttr组合框数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在我的组合框中有多个搜索的Attr。我想要这样做:

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', ["name","age"]);

所以我可以使两个标准自动完成。

So I can make autocomplete on two criterias.

推荐答案

我将假设您正在使用dojo.data.ItemFileReadStore。 searchAttr仅用于您在ComboBox中键入的属性。

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 });

如果你想要你的年龄是动态的,你必须从另一个地方得到它(例如dijit,form元素,dom节点等)。下面是一个例子:当页面加载时,从另一个名为anotherDijit(例如NumberTextBox)的dijit获取年龄:

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() } );

但是,当'anotherDijit'diijt更改时,查询中的年龄值会更改,您有要做一件两件事:

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


  1. 将观察者/事件处理程序附加到适当的anotherDijit事件(例如onChange),这将更新您的ComboBox商店查询中的新'anotherDijit'值。这是一个PUSH方法。

  2. 将一个观察者/事件处理程序附加到适当的ComboBox事件(例如onFocus),该事件处理程序将从anotherDijitdijit中拉取当前值,然后更新存储查询参数。

请注意,您在'query'参数中输入的字段被查询为AND(name = this AND age = that ,等等)。如果您需要更复杂的查询,使用OR和NOT,可以使用dojox.data.AndOrReadStore,例如。

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.

这篇关于searchAttr组合框数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆