2011-01-17 6 views
0

私はDojoで始まり、問題は次のとおりです。 FilteringSelectがあります。私の検索では%john%のようなアイデアが使用されています。dijit.form.Filtering間違った値を選択する

書き込みジョンの後、私はのようにリストを持つことができますので、だから私のフィルタは、リストで選択し、「ジョン」との値になります。

アンドリュー・ジョン
ジョン
ジョン・アレン
サイモン・ジョン

"好きな"アイデアはうまく働く。
問題は、「john」と入力してEnterキーを押したときです。選択された名前は、リストの最初のインスタンス "Andrew John"であり、完全一致の2番目の名前ではありません。どの人がこの問題を解決する方法を持っていますか?

はFilteringSelectの通常のbehaivourは、コンボボックスの最初の要素を取得し、常にあなたの

答えて

0

ありがとうございます。これは通常、完全に一致するためです。私の奴隷がテキストの中で「好き」だったという事実のため、最初の要素は必ずしも正確なマクトではありません。

私の問題を解決するために、私はFilteringSelect.jsを変更しました。したがって、コンボボックスオプションに完全一致があり、この要素が返されているかどうかをチェックします。私の場合、正確なマッチはコンボボックスのリストの2番目、3番目になります。もし私が最初のものを返すのでなければ(前と同じように)。ここで

コード:

> _callbackSetLabel: function( /*Array*/ result, 
         /*Object*/ dataObject, 
         /*Boolean?*/ priorityChange){ 
    // summary: 
    //  Callback function that dynamically sets the label of the 
    //  ComboBox 
    // setValue does a synchronous lookup, 
    // so it calls _callbackSetLabel directly, 
    // and so does not pass dataObject 
    // still need to test against _lastQuery in case it came too late 

if((dataObject && dataObject.query[this.searchAttr] != this._lastQuery) || (!dataObject && result.length && this.store.getIdentity(result[0]) != this._lastQuery)){ 
       return; 
    } 
      if(!result.length){ 
       //#3268: do nothing on bad input 
       //#3285: change CSS to indicate error 
       this.valueNode.value = ""; 
       dijit.form.TextBox.superclass._setValueAttr.call(this, "", priorityChange || (priorityChange === undefined && !this._focused)); 
       this._isvalid = false; 
       this.validate(this._focused); 
       this.item = null; 
      }else{   
       //because the combobox have a like of the word the first element may no be the exact match 
       for(var j = 0; j < result.length; j++) {     
        //check if in the result there is the text that the user typed 
        if(dataObject && result[j].i["id"].toLowerCase() === dataObject.query[this.searchAttr].toLowerCase()) 
        { 
         //return the exact match 
         this.set('item', result[j], priorityChange); 
         return; 
        }     
       } 
       // if there isn't a exact match return the first of the list 
       this.set('item', result[0], priorityChange);     
      } 
     }, 
関連する問題