Kendoui ListView在编辑模式下删除行

Kendoui ListView removes row in edit mode

本文关键字:删除行 模式 编辑 ListView Kendoui      更新时间:2023-09-26

我对kendouis的列表视图有一个问题,如果我编辑一行,另一行将从附加的数据源中删除。当我编辑第一行时,这很好,但当我编辑另一行时,第一行会被删除。

我注意到,在编辑第一行时,首先调用listview的edit函数,但当我编辑第二行数据绑定时,会调用databound,然后再调用edit。

这是代码:

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");

我认为您的主要问题是您的schema位于dataSource.transport.schematransport中,但它应该是dataSource.schema。因此DataSource没有看到指定的schema.model。如果没有模型,它就不知道Id字段是什么,如果没有它,它可能想在编辑时创建新记录,而不是更新它们。


另一个可能的问题可能是将schema.model.id设置为Id,但在schema.model.fields中的字段列表中没有该字段。我会在字段中添加Id。


另一个问题是Kendo DataSource希望服务器返回1个更新的项目,带有匹配的ID,而不是整个项目列表。如果不能将服务器更改为只返回1个项,那么可以将transport.update函数中的逻辑更改为只使用包含1个更新项的数组调用options.success()


您的模板还使用不在schmea.model.fields中的DirectCostFIndirectCostFDynamicPricingType


我无法复制您的服务器请求,但我在这里制作了一个使用本地数据的jsFiddle:http://jsfiddle.net/rally25rs/Lo41dzwp/1/