javascript
  • backbone.js
  • client-side
  • backspace
  • backgrid
  • 2016-03-31 13 views 0 likes 
    0

    Backgridのクライアントサイドフィルタ拡張を使用して検索を実行するとき、コレクションから正しいtotalRecords値を取得できません。Backgridのクライアント側検索からtotalRowsを取得する方法

    特に、キーボードでバックスペースキーを使用すると、

    私はバックスペースを使用して、ゆっくりと入力し、これが正常に動作するようですしていない場合は、次の

    //Search input field - keyup event 
    $("input[name='q']").keyup(function() { 
    
        console.log('searchcontainer input - keyup event'); 
        console.log($(this).val()) 
        console.log($(this).val().length) 
    
        var key = event.keyCode || event.charCode; 
        if (key == 8) { //'8' == backspace key 
         console.log('backspace was keyed!') 
    
         //how do I refresh the 'totalRecords' property on the collection? 
        } 
    
        console.log((_myCollection.state.totalRecords || "0") + " records found.")); 
    
        $("#lblRecordsFound").text((_myCollection.state.totalRecords || "0") + " records found."); 
    }); 
    

    totalRowsは、コレクションの更新をスキップするようにバックスペースが発射されるとき、それはそう(?)?

    バックスペースを使用している場合、現在のtotalRowsを取得するにはどうすればよいですか?コレクションをリセット、取得、更新する必要はありますか?私は不明です。助けて?

    グリッドに現在表示されているtotalRowsが必要です。

    答えて

    0

    backgrid-filter.js拡張を「変更」しました。

    私はそうのように、検索機能を変更:うまく動作し

    /** 
        Takes the query from the search box, constructs a matcher with it and 
        loops through collection looking for matches. Reset the given collection 
        when all the matches have been found. 
    
        If the collection is a PageableCollection, searching will go back to the 
        first page. 
    */ 
    search: function() { 
        var matcher = _.bind(this.makeMatcher(this.query()), this); 
        var col = this.collection; 
        if (col.pageableCollection) col.pageableCollection.getFirstPage({ silent: true }); 
        col.reset(this.shadowCollection.filter(matcher), { reindex: false }); 
        var message = " items found."; 
        if (col.pageableCollection.state.totalRecords == 1) { 
         message = " item found."; 
        } 
        $("#lblRecordsFound").text((col.pageableCollection.state.totalRecords || "0") + message); 
    }, 
    
    。バックグリッドに現在の合計行に簡単にアクセスできる公開されたプロパティがない理由は分かりません。

    関連する問題