【发布时间】:2021-09-10 01:39:06
【问题描述】:
create 方法发送“null”值,delete 方法返回 404 not found,put 方法只清除已编辑的字段。 (所有方法都在邮递员中工作)。
我不确定 Kendo UI 是如何发送到 API 的,但是我的 create 方法等待 body 中的参数,delete 方法等待 URL 中的 id(localhost:3000/api/comment/32) .我的 put 方法还等待正文中的参数 (JSON)。
我可能做错了什么,但我不知道是什么。
这是代码和屏幕(屏幕来自 post 方法):
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Kendo UI Snippet</title>
<link rel="stylesheet" href="styles/kendo.common.min.css">
<link rel="stylesheet" href="styles/kendo.default.min.css">
<link rel="stylesheet" href="styles/kendo.default.mobile.min.css">
<link rel="stylesheet" href="styles/kendo.rtl.min.css">
<link rel="stylesheet" href="styles/kendo.silver.min.css">
<script src="js/jquery.min.js"></script>
<script src="js/kendo.all.min.js"></script>
<script src="js/pako_deflate.min.js"></script>
<script src="js/jszip.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/estilo.css">
<link rel="stylesheet" href="css/daterangepicker.css">
</head>
<body>
<div id="example">
<div id="gridComment"></div>
<script>
$(document).ready(function () {
var commentDataSource = new kendo.data.DataSource({
//autoSync : true,
transport: {
read:{
url: "http://localhost:3000/api/comment",
dataType: "json",
type: "get",
//contentType: "application/json"
},
update: {
url: "http://localhost:3000/api/comment",
dataType: "json",
type: "put",
//contentType: "application/json"
},
create: {
url: "http://localhost:3000/api/comment",
dataType: "json",
type: "post",
},
destroy: {
url: "http://localhost:3000/api/comment",
dataType: "json",
type: "delete",
//contentType: "application/json"
},
},
schema:{
type: "json",
model:{
id: "idvatc",
fields:{
idvatc: { type: "number", editable : false},
commen: { nullable: true},
}
}
},
batch: true,
})
$("#gridComment").kendoGrid({
dataSource : commentDataSource,
editable: true,
confirmation: false,
toolbar: ["save", "cancel","create"],
columns : [{
field : "commen",
title : "Comment"
},
{ command: ["edit","destroy"], title: "Actions", width: 200 }
],
});
});
</script>
</div>
</body>
</html>
【问题讨论】:
标签: javascript node.js kendo-ui