0

助けてください。tbody にバインドされた、計算された監視可能な itemsOnCurrentPage があります。計算されたオブザーバブルは、検索関数を使用して更新されます。しかし、私のUIはまだ同じデータを表示しています。itemsOnCurrentPage の更新されたコンテンツは表示されません。

 var listofcases = ko.observableArray();

    var itemsOnCurrentPage = ko.computed(function () {
        var startIndex = pageSize * currentPageIndex();
        console.log(listofcases.slice(startIndex, startIndex + pageSize));
        return listofcases.slice(startIndex, startIndex + pageSize);
    }, this);

    function SearchCases(username, role, st, ed, ss) {

        $.getJSON('/breeze/Workflow/ListOfCases?UserId=' + username +
                                                '&Role=' + role +
                                                '&RouteId=Annotate&_st=' + st +
                                                '&_ed=' + ed +
                                                '&_ss=' + ss,
                  function (cases) {
                      if (cases.length != 0) {
                          $.each(cases, function (index, _case) {
                              listofcases.push(new CaseDataViewModel(_case));
                          });
                          itemsOnCurrentPage(listofcases());

                      }
                      else {
                          console.log("dddd");
                          listofcases.push(new CaseDataViewModel(_case));
                      }
                  });
    }
4

2 に答える 2

2

関数から計算されたものを呼び出さないでくださいSearchCaseslistofcasesKnockout は、が更新されると自動的に計算を再計算します。次の行を削除します。

itemsOnCurrentPage(listofcases());
于 2013-10-21T14:53:07.080 に答える
0

Artemが言ったように、計算されたものをどこにも設定しないでください。次の行を削除します。

itemsOnCurrentPage(listofcases());

また、計算済みを変更する必要がないため、これを計算済みに渡す必要はありません。これが問題の原因であると思われます。計算されたものをこれに置き換えてみてください:

var itemsOnCurrentPage = ko.computed(function () {
        var startIndex = pageSize * currentPageIndex();
        console.log(listofcases().slice(startIndex, startIndex + pageSize));
        return listofcases().slice(startIndex, startIndex + pageSize);
    });
于 2013-10-22T06:24:09.357 に答える