javascript-新添加的数据未正确保存在kendo网格中

编程之家收集整理的这篇文章主要介绍了javascript-新添加的数据未正确保存在kendo网格中编程之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

完成以下操作时,网格行为不符合预期.>添加新记录>然后按网格中的更新按钮(新添加的行)>然后在保存之前按取消.完成上述操作后,新添加的行将消失.linktojsfiddle<!DOCTYPEhtml><htmllang="en"><head><metacharset="utf-8"><title>DemoGridApp<itle

完成以下操作时,网格行为不符合预期.

>添加新记录
>然后按网格中的更新按钮(新添加的行)
>然后在保存之前按取消.

完成上述操作后,新添加的行将消失.
link to js fiddle

<!DOCTYPE HTML>
<HTML lang="en">
<head>
    <Meta charset="utf-8">
    <Title>Demo GrID App</Title>
    <!-- CDN-based stylesheet reference for Kendo UI DataViz -->
    <link rel="stylesheet" href="http://cdn.kendostatic.com/2012.2.710/styles/kendo.default.min.CSS">
     <link rel="stylesheet" href="http://cdn.kendostatic.com/2012.2.710/styles/kendo.common.min.CSS">
            <!-- CDN-based script reference for jquery; utilizing a local reference if offline -->
    <script src="http://AJAX.GoogleAPIs.com/AJAX/libs/jquery/1.8.2/jquery.min.Js"></script>
       <!-- CDN-based script reference for Kendo UI DataViz; utilizing a local reference if offline -->
    <script src="http://cdn.kendostatic.com/2012.2.710/Js/kendo.all.min.Js"></script>

</head>
<body>
    <header>
        <h1>Demo GrID App</h1>
    </header>

<div ID="grID"></div>
          <script>
          var firstnames = ["Nancy", "Andrew", "Janet", "Margaret", "Steven", "Michael", "Robert", "Laura", "Anne", "Nige"],
    lastnames = ["Davolio", "Fuller", "Leverling", "Peacock", "Buchanan", "Suyama", "King", "Callahan", "Dodsworth", "White"],
    citIEs = ["Seattle", "Tacoma", "Kirkland", "Redmond", "London", "Philadelphia", "New York", "Seattle", "London", "Boston"],
    Titles = ["Accountant", "Vice PresIDent, Sales", "Sales Representative", "Technical Support", "Sales Manager", "Web Designer",
    "Software Developer", "InsIDe Sales Coordinator", "ChIEf Techical Officer", "ChIEf Execute Officer"],
    birthDates = [new Date("1948/12/08"), new Date("1952/02/19"), new Date("1963/08/30"), new Date("1937/09/19"), new Date("1955/03/04"), new Date("1963/07/02"), new Date("1960/05/29"), new Date("1958/01/09"), new Date("1966/01/27"), new Date("1966/03/27")];

function crea@R_404_6704@ndomData(count) {
    var data = [],
        Now = new Date();
    for (var i = 0; i < count; i++) {
        var firstname = firstnames[Math.floor(Math.random() * firstnames.length)],
            lastname = lastnames[Math.floor(Math.random() * lastnames.length)],
            city = citIEs[Math.floor(Math.random() * citIEs.length)],
            Title = Titles[Math.floor(Math.random() * Titles.length)],
            birthDate = birthDates[Math.floor(Math.random() * birthDates.length)],
            age = Now.getFullYear() - birthDate.getFullYear();

        data.push({
            ID: i + 1,
            Firstname: firstname,
            Lastname: lastname,
            City: city,
            Title: Title,
            BirthDate: birthDate,
            Age: age
        });
    }
    return data;
}

function generatePeople(itemCount, callback) {
    var data = [],
        delay = 25,
        interval = 500,
        starttime;

    var Now = new Date();
    setTimeout(function() {
        starttime = +new Date();
        do {
            var firstname = firstnames[Math.floor(Math.random() * firstnames.length)],
                lastname = lastnames[Math.floor(Math.random() * lastnames.length)],
                city = citIEs[Math.floor(Math.random() * citIEs.length)],
                Title = Titles[Math.floor(Math.random() * Titles.length)],
                birthDate = birthDates[Math.floor(Math.random() * birthDates.length)],
                age = Now.getFullYear() - birthDate.getFullYear();

            data.push({
                ID: data.length + 1,
                Firstname: firstname,
                Lastname: lastname,
                City: city,
                Title: Title,
                BirthDate: birthDate,
                Age: age
            });
        } while(data.length < itemCount && +new Date() - starttime < interval);

        if (data.length < itemCount) {
            setTimeout(arguments.callee, delay);
        } else {
            callback(data);
        }
    }, delay);
}
                $(document).ready(function() {
                    $("#grID").kendoGrID({

                        dataSource: {
                            data: crea@R_404_6704@ndomData(10),


                            schema: {
                                model: {
                                    ID:"Firstname",
                                    fIElds: {
                                        Lastname: { type: "string" },
                                        City: { type: "string" },
                                        Title: { type: "string" },
                                        BirthDate: { type: "date" },
                                        Age: { type: "number" }
                                    }
                                }
                            },
                            pageSize: 10
                        },
                        height: 500,
                        wIDth:300,
                         toolbar: ["create"],
                        scrollable: true,
                        sortable: true,
                        fil@R_404_6704@ble: true,
                        pageable: {
                            input: true,
                            numeric: false
                        },
                        columns: [

                            {
                                fIEld: "Lastname",
                                Title: "Last name",

                            },
                            {
                                fIEld: "City",

                            },
                            {
                                fIEld: "Title"
                            },
                            {
                                fIEld: "BirthDate",
                                Title: "Birth Date",
                                template: '#= kendo.toString(BirthDate,"MM/dd/yyyy") #'
                            },
                            {
                                fIEld: "Age",
                                wIDth: 50
                            },
                              { command: ["edit", "destroy"], Title: "&nbsp;", wIDth: "210px" },
                        ],
                         editable: "inline"
                    });
                });
            </script>
    <div role="main">
    </div>
    <footer>
    </footer>
</body>
</HTML>

解决方法:

该行为是预期的.问题来自这样一个事实,即新创建的记录没有ID,这就是为什么将它们视为新记录的原因.您可以使用isNew()方法进行检查.

当您取消对新记录(尚未同步)的编辑时,它将被删除.该操作与以下操作相同:按“添加新记录”,然后按“取消”.

这是an example,它演示了如何使用本地数据实现CRUD操作.

        transport: {
            read: function(o) {
                //pass the date
                o.success(data);
            },
            create: function(o) {
                var item = o.data;
                //assign a unique ID and return the record
                counter++;
                item.ID = counter;
                o.success(item);
            },
            update: function(o) {
                //edit the local array and mark the operation as successful
                o.success();
            },
            destroy: function(o) {
                //edit the local array and mark the operation as successful
                o.success();   
            }
        }

总结

以上是编程之家为你收集整理的javascript-新添加的数据未正确保存在kendo网格中全部内容,希望文章能够帮你解决javascript-新添加的数据未正确保存在kendo网格中所遇到的程序开发问题。

如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。

jQuery文章

由于是触摸屏,所以需要一款JS虚拟键盘。上网找了一个好用的VirtualKeyboard,作了修改。 修改该插件参考的博客文章:http://www.cnblogs.com/xinggong/arch
HashMap代码(这种实现方式是错误的,错误原因:代码中_map、_length变量是HashMap的所有实例共用的): /** * HashMap * 2021年09月09日 */ (functi
一、引用CSS和JS:View Code二、HTML:View Code三、JS:$(function () { var total = parseInt(&quot;@(ViewBag.total)
JS数字键盘,JS小键盘CSS代码:#numberkeyboard{ border: 1px solid #b3b3b3; background: #f2f3f7; height: 285px; ma
C.js代码: /** * 有BUG */ (function (global) { var _id; var _map; var _length; global.C = function () {
一、节点模糊搜索功能:搜索成功后,自动高亮显示并定位、展开搜索到的节点。二、节点异步加载:1、点击展开时加载数据;2、选中节点时加载数据。前台代码如下:View Code View Code后台代码(
需求:页面显示教师信息列表,列表中每一条数据显示图片滚动插件,每张图片的长宽及长宽比例各不相同。 前提条件:美工把静态页面写好 HTML代码: @using Models; @{ List&lt;cm
示例代码: marker.addEventListener(&quot;click&quot;, function(){ if (!window.markerClicked) { window.mar
微信公众号搜索 “ 程序精选 ” ,选择关注!
微信公众号搜 "程序精选"关注