博士剑道UI与数据源(CRUD)


Php Kendo UI With datasource (CRUD)

我正在努力使用Kendo UI获得CRUD的功能?我的创建和更新选项似乎不起作用,但我的阅读起作用,有什么帮助吗?我已经学习了很多教程,但就是无法让它发挥作用。提前谢谢。

这里是我的代码,这是我的Index.php文件:

<!DOCTYPE html>
<html>
<head>
<link href="styles/kendo.common.min.css" rel="stylesheet" />
<link href="styles/kendo.default.min.css" rel="stylesheet" />
<link href="styles/kendo.dataviz.min.css" rel="stylesheet" />
<link href="styles/kendo.dataviz.default.min.css" rel="stylesheet" />
<script src="js/jquery.min.js"></script>
<script src="js/angular.min.js"></script>
<script src="js/kendo.all.min.js"></script>
</head>
<body>
<div id="example">
<div id="grid"></div>
<script>
    $(document).ready(function () {
            dataSource = new kendo.data.DataSource({
                batch: true,
                transport: {
                    read: "data/ussd.php"
                },
                update: {
                    url: "data/ussd.php",
                    type: "POST"
                },
                create: {
                    url: "data/create.php",
                    type: "PUT"
                },
                parameterMap: function(options, operation){
                    if(operation !== "read" && option.models){
                        return{models : kendo.string(options.models)}
                    }
                },
                pageSize: 20,
                schema: {
                    data: "data",
                    model: {
                        id: "id",
                        fields: {
                             id: {editable: false, nullable: true},
                             msisdn: {editable: true, type: "number"},
                             company: {editable: true},
                             description: {editable: true},
                             ussd: {editable: true},
                             updated: {editable: true, type: "date"},
                             added: {editable: true, type: "date"}
                        }
                    }
                },
                serverFiltering: true,
                serverSorting: true
            });
        $("#grid").kendoGrid({
            dataSource:  dataSource,
            pageable: true,
            filterable: true,
            sortable: true,
            height: 500,
            toolbar: ["create", "save", "cancel"],
            columns: [
                { field: "id", title: "ID", width: "45px" },
                { field: "msisdn", title: "MSISDN", width: "75px" },
                { field: "company", title: "Company", width: "100px" },
                { field: "description", title:"Description", width: "100px" },
                { field: "ussd", title: "USSD", width: "100px" },
                { field: "updated", title: "Updated", width: "100px" },
                { field: "added", title: "Added", width: "100px" },
                { command: ["edit", "destroy"], title: "&nbsp;", width: "140px" }],
            schema: {
                model: { id: "id" }
            },
            editable: "inline",
            navigable: true
        });

    });

</script>
</div>
</body>
</html>

这就是我所改变的,基本上URL和类型是不正确的,并且没有遵循正确的路径

$(document).ready(function () {
        dataSource = new kendo.data.DataSource({
            transport: {
                read: "data/whitelist.php?type=read",
                update: {url:"data/whitelist.php?type=update", type:"POST"},
                create: {url:"data/whitelist.php?=create",type:"POST"},
                destroy: {url:"data/whitelist.php?type=destroy",type:"POST"}
            },

            batch: false,
            pageSize: 20,
            schema: {
                model: {
                    id: "id",
                    fields: {
                        id: {editable: false, nullable: true},
                        msisdn: {editable: true, type: "number"},
                        company: {editable: true},
                        description: {editable: true},
                        ussd: {editable: true},
                        updated: {editable: true, type: "date"},
                        added: {editable: true, type: "date"}
                    }
                }
            },
            serverFiltering: true,
            serverSorting: true
        });
        $("#grid").kendoGrid({
            dataSource:  dataSource,
            pageable: true,
            filterable: true,
            sortable: true,
            height: 430,
            toolbar: [{name: "create", text: "Add New"}, "save", "cancel"],
            columns: [
                { field: "id", title: "ID", width: "26px" },
                { field: "msisdn", title: "MSISDN", width: "50px" },
                { field: "company", title: "Company", width: "65px" },
                { field: "description", title:"Description", width: "65px" },
                { field: "ussd", title: "USSD", width: "50px" },
                { field: "updated", title: "Updated", width: "70px" },
                { field: "added", title: "Added", width: "70px" },
                { command: [{text:"Edit", name:"edit"}, {text:"Delete",name:"destroy"}], title: " ", width: "80px" }],
            editable: "inline",
            navigable: true

        });
    });
{                    read: "data/ussd.php"
                },
                update: {
                    url: "data/ussd.php",
                    type: "POST"
                },
                create: {
                    url: "data/create.php",
                    type: "PUT"
                }

您的Read和update都使用相同的php文件。

create中的PUT类型是什么?

只需将更新url更改为其他php文件,并获取发布的值即可在数据库中运行查询。并将create的类型也更改为POST,因为你也在为其他人使用POST。。

在更新部分更改此

url: "data/ussd.php",

进入

url: "data/update.php",

并尝试获取我之前说过的发布值。看看是否适合你。