2011-09-02 6 views
2

코드 : 내 모델센차 터치 filterBy 스토어

this.searchField = new Ext.form.Text({ 
      displayField: 'name', 
      valueField: 'name', 
      editable: true, 
      forceSelection: true, 
      triggerAction: 'all', 
      emptyText: 'Search...', 
      selectOnFocus: true 
    }); 

this.searchButton = new Ext.Button({// The button press will invoke the search action 
     text: 'Go', 
     handler: this.searchButtonTap, 
     scope: this 
    }); 

    this.topToolbar = new Ext.Toolbar({ 
        items: [ 
       { xtype: 'spacer' },  
        this.searchField, 
        this.searchButton, 
        { xtype: 'spacer' }, 
       ] 
     }); 

searchButtonTap: function() { 

     var searchText = this.searchField.getValue(); 
     console.log(searchText); 
     //console.log(this.myappsList.store.getCount()); 
     console.log(this.myappsList.store.filter('name', searchText)); 
     //this.myappsList.store.filter(searchText); 

    }, 

내가 네 개의 필드가 : 내가 뭘 여기하려하는 것은

이름, 나이, 성별, Charecteristic

을 :

사용자가 검색 필드에 검색어를 쓰고 검색 버튼 인을 누르면 검색하려는 목록이 길기 때문에 페이지의 목록에 내 데이터베이스의 콘텐츠가 표시됩니다.처리기가 호출되어 쿼리의 이름과 비슷한 이름의 목록을 필터링하고 표시하려고 시도했습니다. filterBy도 시도했지만 작동하지 않았습니다. 뭐가 잘못 됐는지 알려주시겠습니까?

감사합니다.

이 방법으로 시도 할 수

답변

5

:

searchButtonTap: function() { 
     var searchTerm = this.searchField.getValue(); 
     if (searchTerm) { 
      this.myappsList.store.filterBy(function(record){ 
      var fieldData = record.data.city.toLowerCase().indexOf(searchTerm); 
      if (fieldData > -1) 
       return record; 
      }); 


     } 
     else { 
      this.myappsList.store.clearFilter(); 
      } 
    },