将新行添加到空的剑道网格中
add new row to empty kendo grid
我有这个网格
$("#email-grid").kendoGrid({
dataSource: {
transport: {
read: {
url: "operations/get_emails_sales_reps.php?salesRepsId=" + salesRepsId,
type: "GET"
},
update: {
url: "operations/edit_email.php?salesRepsId=" + salesRepsId,
type: "POST",
complete: function (e) {
$("#email-grid").data("kendoGrid").dataSource.read();
}
},
destroy: {
url: "operations/delete_email.php",
type: "POST",
complete: function (e) {
$("#email-grid").data("kendoGrid").dataSource.read();
}
},
create: {
url: "operations/add_email.php?salesRepsId=" + salesRepsId,
type: "POST",
complete: function (e) {
$("#email-grid").data("kendoGrid").dataSource.read();
}
},
},
schema: {
data: "data",
total: "data.length", //total amount of records
model: {
id: "SalesRepId",
fields: {
EmailType: {
defaultValue: {
EmailTypeId: 2,
EmailTypeName: "Home"
}
},
EmailText: {
type: "string"
},
IsMainEmail: {
type: "boolean"
}
}
}
},
pageSize: 5,
},
height: 250,
filterable: true,
sortable: true,
pageable: true,
reorderable: false,
groupable: false,
batch: true,
navigatable: true,
toolbar: ["create", "save", "cancel"],
editable: true,
columns: [{
field: "EmailType",
title: "Type",
editor: EmailTypeDropDownEditor,
template: "#=EmailType.EmailTypeName#"
}, {
field: "EmailText",
title: "Email",
}, {
field: "IsMainEmail",
title: "Main?",
width: 65,
template: function (e) {
if (e.IsMainEmail == true) {
return '<img align="center" src ="images/check-icon.png" />';
} else {
return '';
}
}
// hidden: true
}, {
command: "destroy",
title: " ",
width: 90
},
]
});
服务器端的代码(get_emails_sales_reps.php)
<?php
require_once ("../lib/salesrep.php");
require_once ("../lib/helper.php");
// add the header line to specify that the content type is JSON
header("Content-type: application/json");
$options = array();
$result = SalesRep::getRepEmails($_GET["salesRepsId"]);
if (isset($result) && $result != null) {
$result = _object_to_array($result);
if (isset($result[0]) && is_array($result)) {
for ($i = 0; $i < count($result); $i++) {
$result[$i]["EmailType"] = array("EmailTypeName" => $result[$i]["EmailType"], "EmailTypeId" => $result[$i]["EmailTypeId"]);
}
} else {
$result["EmailType"] = array("EmailTypeName" => $result["EmailType"], "EmailTypeId" => $result["EmailTypeId"]);
}
if (isset($result) || $result != null) {
echo "{'"data'":" . json_encode($result) . "}";
} else {
echo "{'"data'": {} }";
}
}
?>
当网格有一个或多个记录时,我可以添加新记录而不会出现任何错误,但当没有记录时,网格会尝试添加新记录。我收到这个错误
未捕获的类型错误:无法读取未定义的属性"length"
请问,我该怎么修??
我通过编辑php文件解决了这个问题。当结果为null(空)时,我必须返回一个空的json数组,如
else {
// the result is null
echo "{'"data'": [] }";
}
相关文章:
- 如何从rails中的代码中删除新行( )
- 拆分文本以每隔n个字符添加一行新行,并注意空格
- 如何在脚本上添加新行
- 在不刷新整个网格的情况下,向Asp.net网格视图添加新行
- 字符串中的
标记未正确在 HTML 中创建新行 - JavaScript-如果以前不存在文本,如何从文本区域删除新行
- 反应中的新行
- 阻止ReSharper将JavaScript函数参数放到新行中
- HTML表内容:如果行很长,如何在新行中显示部分内容
- dhtmlx添加新行并启动单元格编辑器
- 如何在剑道网格中添加具有预定义数据的新行
- 使用一些默认值在剑道网格中添加新行
- 剑道网格 - 单击“添加新行”按钮后,获取剑道网格未捕获的类型错误:无法读取“名称”空的属性
- 如何立即开始编辑添加到网格中的新行/列
- 如何在ui网格中的特定索引处添加新行
- 将新行添加到空的剑道网格中
- 剑道UI网格内联-在网格上的特定位置插入新行
- 向网格添加新行
- 如何使整个网格视图行可单击并打开新链接
- 剑道网格:取消编辑删除新行