Dojo Select 小部件没有选择性地从数据存储中查询内容
我一直在尝试使用 ItemFileReadStore 的查询功能来过滤选择小部件的可选选项列表,但似乎我的查询对小部件没有影响。查询是通过另一个选择小部件的 onChange 事件完成的,我的目标是当一个小部件选择一个值时,另一个小部件不再包含该值作为选项)。 看看“Codependent FilteringSelect/ComboBox widgets”示例在 dojo 的文档站点。但按照这个例子,我没有得到任何结果。 我尝试使用的小部件如下:
var sel1 = new dijit.form.Select({
id:"sel1",
name: "sel1",
required: true,
style: "width: 170px;",
query: {value: "*" },
store: selStore
},"sel1");
我还有另一个小部件 sel2,它类似并使用相同的商店。我的“onChange”事件具有以下代码:
dojo.connect(element, 'onChange', function(event){
dojo.forEach([sel1, sel2], function(element){
if(element.getValue() !== event){
element.attr("query", "{value: !" + event + "}");
console.log("querying", element, element.query);
element.store.fetch();
}
});
因此,我得到的控制台打印输出返回正确的元素,并且 element.query 的形式为:{value: !val1},但在任一选定小部件的下拉菜单。 如果有人可以提供任何帮助,我们将不胜感激。 谢谢
I have been trying to use the query functionality of the ItemFileReadStore to filter the list of a select widget's selectable options and it seems that my queries are having no effect on the widget. The query is being done through the onChange event of another select widget, my objective is that when one widget selects a value the other one no longer contains that value as an option).
This seemed fairly simple looking at the "Codependent FilteringSelect/ComboBox widgets" example at dojo's docs site. But following this example has left me with no results.
My widget that I am trying to use is below:
var sel1 = new dijit.form.Select({
id:"sel1",
name: "sel1",
required: true,
style: "width: 170px;",
query: {value: "*" },
store: selStore
},"sel1");
I also have another widget sel2 which is similar and uses the same store. My 'onChange' event for both has the following code:
dojo.connect(element, 'onChange', function(event){
dojo.forEach([sel1, sel2], function(element){
if(element.getValue() !== event){
element.attr("query", "{value: !" + event + "}");
console.log("querying", element, element.query);
element.store.fetch();
}
});
As a result of this the console printout I get returns the correct element and the element.query is of the form: {value: !val1}, but nothing is being altered in the dropdown of either of the select widgets.
If anyone could be of any assistance it would be very much appreciated.
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
表达式 !val1 需要加引号吗?
does the expression !val1 need to be quoted?
经过一些搜索和实验后,我发现 dijit.form.Select 在查询其数据存储时不像 Filtered Select 小部件那样工作。为了查询数据存储,您必须调用 setStore 方法,向其传递当前正在使用的同一存储以及 fetchArg 形式的查询对象(即 {query: {value: blah}})。请参阅此处的获取文档。
对于关于找出如何在获取所有值 != value1 的效果中从存储中消除选项的问题的后半部分,您可以使用专为这些类型的查询设计的存储,称为 AndOrReadStore 扩展自 ItemFileReadStore 并与 dijit.form.Select 小部件兼容,只需使用 NOT 关键字即可。
After some search and experimentation I have found that dijit.form.Select does not work like the Filtered Select widget when it comes to querying its datastore. In order to query the datastore you must call the setStore method, passing it the same store currently being used and a query object of the form of a fetchArg (i.e. {query: {value: blah}}). See the fetch docs here.
For the second half of the question about finding out how to eliminate options from the store in the effect of fetching all values != value1 you can use a store designed for these types of queries known as the AndOrReadStore which extends from ItemFileReadStore and is compatible with the dijit.form.Select widget, and simply use the NOT keyword.