2017-07-14 85 views
0

多不必要的請求,我有以下的HTML頁:(頁面的一部分)Aurelia路上,劍道網 - 爲數據源

<ak-multiselect k-data-text-field="text" 
    k-data-value-field="value" k-value.two-way="selectPaymentType" k-data-source.bind="dataPaymentType" 
</ak-multiselect> 
<br/> 
<ak-multiselect k-data-text-field="text" 
    k-data-value-field="value" k-value.two-way="selectPaymentResult" k-data-source.bind="dataPaymentResult" 
</ak-multiselect> 
<br/> 
<button ak-button="k-icon: ungroup; k-widget.bind: button" k-on-click.delegate="GetTransaction()">Get Transactions</button> 
<br/> 
<div ref="gridTransaction"></div> 

這是我的視圖模型:

export class Transaction { 
    selectPaymentType; 
    selectPaymentResult; 
    gridTransaction; 

    dataPaymentType = [ 
    { text: 'Mobile Payment', value: '0' }, 
    { text: 'Card Present Payment', value: '1' }, 
    { text: 'Cash Payment', value: '2' } 
    ] 

    dataPaymentResult = [ 
    { text: 'Pending', value: '0' }, 
    { text: 'Approved', value: '1' }, 
    { text: 'Declined', value: '2' } 
    ] 

    buildTransactionFilters() { 
     var filtersTotal = []; 

     var filtersPaymentType = []; 
     var selectPaymentType = this.selectPaymentType; 
     if (selectPaymentType != null && selectPaymentType.length > 0) { 
      selectPaymentType.forEach(function (item, i, dataItems) { 
       filtersPaymentType.push({ 
        field: "paymentType", 
        operator: "eq", 
        value: item 
       }); 
      }); 
     } 
     var filterPaymentType = { 
      logic: "or", 
      filters: filtersPaymentType 
     }; 

     var filtersPaymentResult = []; 
     var selectPaymentResult = this.selectPaymentResult; 
     if (selectPaymentResult != null && selectResult.length > 0) { 
      selectPaymentResult.forEach(function (item, i, dataItems) { 
       filtersPaymentResult.push({ 
        field: "result", 
        operator: "eq", 
        value: item 
       }); 
      }); 
     } 
     var filterPaymentResult = { 
      logic: "or", 
      filters: filtersPaymentesult 
     }; 

     if (filtersPaymentType.length > 0) 
      filtersTotal.push(filterPaymentType); 
     if (filtersPaymentResult.length > 0) 
      filtersTotal.push(filterPaymentResult); 
     return { 
      logic: "and", 
      filters: filtersTotal 
     }; 
    } 

    GetTransaction() { 
     var filters = this.buildTransactionFilters(); 
     var datasourceTransaction = new kendo.data.DataSource({ 
      type: "json", 
      transport: { 
       read: { 
        type: "POST", 
        contentType: "application/json; charset=utf-8", 
        url: "api/getTransaction", 
        cache: false 
       }, 
       parameterMap(data, operation) { 
        if (data.models) { 
         return JSON.stringify({ products: data.models }); 
        } else if (operation === "read") { 
         return JSON.stringify(data); 
        } 
       } 
      }, 
      filter: filters, 
      schema: { data: "data", total: "total", aggregates: "aggregates"}, 
      serverPaging: true, 
      serverSorting: true, 
      serverFiltering: true, 
      pageSize: 10 
     }) 

     var $grid = $(this.gridVM).kendoGrid({ 
      dataSource: datasourceTransaction, 
      pageable: { refresh: true, pageSizes: true, buttonCount: 5 }, 
      scrollable: true, 
      sortable: true, 
      columns: [{ field: "publicId", title: "Public Id", filterable: false}, 
       { field: "initiated", title: "Initiated", filterable: false, type: "datetime"}, 
       {field: "total", title: "Total", filterable: false} 
      ] 
     }).data("kendoGrid"); 
    } 
} 

我選擇必要的過濾,按下按鈕並查看正確的數據。然後我更換過濾器並按下按鈕 - 數據再次正確。但是,如果我更改了頁數或記錄編號,我可以在網絡中看到我以前的所有請求中的。結果 - 我在網格中看到我以前的請求(使用不同的過濾器)的響應速度更快。先前請求的數量 - 點擊按鈕的次數。

我該如何修復它並僅從上次請求獲取數據?

回答