1

ノックアウトを使用して Pager コントロールを作成しています。「currentPageIndex」、「itemsPerPage」、「totalRecords」などのプロパティを持つviewModel(PaginatorViewModel)があります。各ページには、ページのTOPに1つ、Bottomにもう1つの2つのページネーションコントロールがあります。

場合によっては、タブがあり、各タブに 2 つのページネーション コントロール (TOP と Bottom) があります。

Tab1 にいて、ページ 2 (currentPageIndex=2) に移動すると、Tab2 のページネーション コントロールも currentPageIndex を 2 として表示します。

すべてのタブで PaginatorViewModel を使用したいのですが、複数のインスタンス、つまりタブごとに 1 つのインスタンスを維持したいと考えています。

どうすればこれを達成できますか。

これが私のViewModelです。

var CustomPaginator = {        
        //The current page index of the post being displayed.
        currentPageIndex: ko.observable(1),
        //specifies the page options
        pageOptions : ko.observableArray([25, 50, 100, 200]),

        //specifies the PageOptions will be shown or not.
        showOptions : ko.observable(true),                
        //The maximum number of topics displayed per page.
        itemsPerPage : ko.observable(25),
        //Specifies the total no of records
        totalRecords : ko.observable(1),
        isVisible : ko.observable(false),
        //pageIndex is bounded to the text box, and the CurrentPageIndex contains the actual value.
        // this is to avoid the notifying the subscribers when the user enters the out of range values
        // like 0,and N , where N > no of pages
        pageIndex : ko.observable(1)
  };

このインスタンスを作成するにはどうすればよいですか。

ありがとう、ラメッシュ

4

1 に答える 1

3

ページネーターごとにビューモデルを作成し、使用するページの要素にそれぞれをバインドします。

var page1 = new CustomPaginator();
ko.applyBindings(page1, $('#page1')[0]);

これをそれぞれに行います。必要に応じて、同じビューモデルをページのさまざまな部分にバインドすることもできます。

ビュー モデルの新しいインスタンスを作成できるように、ビュー モデルの定義方法を変更する必要があります。

var CustomPaginator = function()
{
    //your view model properies here
} 
于 2013-04-16T18:14:35.200 に答える