Kendoui ListView在编辑模式下删除行
Kendoui ListView removes row in edit mode
我对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.schema
的transport
中,但它应该是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
中的DirectCostF
、IndirectCostF
和DynamicPricingType
。
我无法复制您的服务器请求,但我在这里制作了一个使用本地数据的jsFiddle:http://jsfiddle.net/rally25rs/Lo41dzwp/1/
相关文章:
- 手持:删除行后更新渲染器
- 在表中找到元素时删除行
- 无法使用jQuery从表中删除行
- 向具有唯一Id的表添加/删除行
- 在页面加载时删除CSS模式Flash
- 当行增加时自动递增序列号,并在 jQuery 中删除行时自动重新调整编号顺序
- 使用 for 循环基于
id 从表中删除行 - 无法从表中删除行
- 使用 Javascript 动态删除行.我的代码有什么问题
- 删除行中多余元素的函数
- 使用php中的单选按钮从MS SQL SERVER中删除行
- 按类名从表中删除行
- 类型错误:无法读取属性'行'使用javascript删除行时为null
- 确认删除的模式对话框
- 单击a href删除行(TR)
- 使用ajax从数据库Mvc中的表中删除行
- Kendoui ListView在编辑模式下删除行
- 在父猫模式的数组中删除子模式中的单个行
- Bootstrap 3:添加确认模式框jQuery内联删除行
- Javascript删除行匹配模式