2014-11-05 54 views
0

我有一個問題,肯德斯的列表視圖,如果我編輯一行另一個從附加的數據源中刪除。這在我編輯第一行時正常工作,但是當我編輯另一行時,第一行被刪除。Kendoui ListView刪除在編輯模式下的行

我注意到在編輯第一行listview的編輯函數時會先調用,但是當我編輯第二行數據綁定時,會調用databound然後編輯。

這裏是代碼:

var dataSource = new kendo.data.DataSource({ 

    transport: { 
    read: function (options) {  
    options.success(lst); 
    }, 
    update: function (options) { 
     oThis.httpService.Post('api/DynamicPricing/UpdateDynamicItem', lst) 
          .success(function (data, status) {  
           options.success(data); 
          });  
        }, 
       schema: { 
        model: { 
         id: "Id", 
         fields: { 
          Name: { type: "string" }, 
          CategoryF: { type: "string" }, 
          DirectCost: { type: "number" }, 
          IndirectCost: { type: "number" }, 
          StrategyType: { type: "string" }, 
          Value: { type: "string" }, 
          OverridePrice: { type: "number" }, 
          Current: { type: "string" } 
         } 
        } 
       } 
      }); 

      list = $('#listcontent').kendoListView({ 
       template: kendo.template('<table cellpadding="3px" class="gridDynamicPricingContent"><tr> \ 
              <td width="100px">#:Name#</td> \ 
              <td width="100px">#:CategoryF#</td> \ 
              <td width="100px" align="right">#:DirectCostF#</td> \ 
              <td width="100px" align="right">#:IndirectCostF#</td> \ 
              <td width="100px">#:StrategyType#</td> \ 
              <td width="50px">#:Value#</td> \ 
              <td width="100px" style="text-align:right; padding-right:5px;" >#:OverridePriceF#</td> \ 
              <td width="100px">#:Current#</td > \ 
              <td width="100px"><a class="k-button k-edit-button" href = "\\#"><span class="k-icon k-edit"></span></a></td>\ 
             </tr></table>'), 
       editTemplate: kendo.template('<table class="gridDynamicPricingContent k-state-selected"><tr> \ 
              <td width="100px">#:Name#</td> \ 
              <td width="100px">#:CategoryF#</td> \ 
              <td width="100px" align="right">#if(DynamicPricingType==5){# #:data.DirectCost# #}else{#<input type="number" style="width:60px;" class="k-textbox" data-bind="value:DirectCost" name="DirectCost" />#}#</td> \ 
              <td width="100px" align="right">#:IndirectCost#</td> \ 
              <td width="100px">#:StrategyType#</td> \ 
              <td width="50px">#:Value#</td> \ 
              <td width="100px" style="text-align:right; padding-right:5px;">#if(DynamicPricingType==4 || DynamicPricingType==5){#<input type="number" class="k-textbox" style="width:60px;" data-bind="value:OverridePrice" name="OverridePrice" />#}else{# #:data.OverridePrice# #}#</td> \ 
              <td width="100px">#:Current#</td > \ 
              <td width="100px"><a class="k-button k-button-icontext k-update-button" href="\\#"><span class="k-icon k-update"></span></a></td> \ 
             </tr></table>'), 
       dataSource: dataSource, 
       selectable: true, 
       dataBound: function() { 
        $('#listcontent').prepend(header); 
       }  
      });//.data("kendoListView"); 
+0

什麼是「API/DynamicPricing/UpdateDynamicItem的迴歸?只是一個項目正在更新,或所有項目的整個列表? – CodingWithSpike 2014-11-05 21:30:52

+0

它返回所有項目並且它是不相關的,因爲不會調用更新。 – Haris 2014-11-10 07:33:15

回答

0

我覺得你的主要問題是,你有你的schema裏面transportdataSource.transport.schema,但它應該是dataSource.schema。所以DataSource沒有看到你指定的schema.model。如果沒有該模型,它不知道Id字段是什麼,如果沒有,它可能想要在編輯時創建新記錄,而不是更新它們。


另一個可能的問題可能是你有schema.model.id設置爲Id,但你沒有在你的schema.model.fields字段列表該字段。我會將Id添加到字段中。


的另一個問題是,劍道數據源預計服務器返回1個更新的項目,與匹配的ID,而不是項目的整個列表。如果無法將服務器更改爲僅返回1個項目,則可以將transport.update函數中的邏輯更改爲僅調用options.success(),其中包含1個更新項目的數組。


你的模板也使用DirectCostFIndirectCostFDynamicPricingType這是不是在你的schmea.model.fields


我無法重現你的服務器的請求,但我做的是,這裏使用本地數據的jsfiddle:http://jsfiddle.net/rally25rs/Lo41dzwp/1/

相關問題