2012-08-24 27 views
1

我想實現這樣的事情:道場過濾選擇正則表達式查詢

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

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

這可能嗎?

我正在使用ItemFileReadStore作爲該FilteringSelect的商店。

回答

1

請參閱Fuzzy Matches on dijit.form.ComboBox/dijit.form.FilteringSelect Subclass如果您想要多走一步。但是,這用於過濾用戶輸入。

要在過濾選擇中打開/輸入任何內容之前過濾掉條目,請繼續執行準備工作。一個簡單的字符串不會接受OR運算符,但使用RegExp

ItemFileReadStore docs on query

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

作爲一個起點,所有的項目都出現在店裏,要利用queryengine的方式是通過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')) 
      }); 
     } 

    }) 

例如使用

http://jsfiddle.net/LuUbT/
+0

謝謝,但我已經嘗試過,沒有任何作品!我正在使用json作爲商店(不是服務器上的url) – Damian0o

+0

然後你做錯了:)看到我編輯的答案或上面鏈接的小提琴 – mschr

+0

應該是新的RegExp(「/ ^(12 | 13)$ /」 )'或'new RegExp(「^(12 | 13)$」)'? (帶有斜線或不帶) – mbomb007