Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 新添加的数据未正确保存在剑道网格中_Javascript_Jquery_Kendo Ui_Kendo Dataviz - Fatal编程技术网

Javascript 新添加的数据未正确保存在剑道网格中

Javascript 新添加的数据未正确保存在剑道网格中,javascript,jquery,kendo-ui,kendo-dataviz,Javascript,Jquery,Kendo Ui,Kendo Dataviz,执行以下操作时,网格行为不符合预期 添加新记录 然后按网格中的更新按钮(新添加的行) 然后在保存前按取消 当上述操作完成时,新添加的行将消失。 演示网格应用程序 演示网格应用程序 var firstNames=[“南希”、“安德鲁”、“珍妮特”、“玛格丽特”、“史蒂文”、“迈克尔”、“罗伯特”、“劳拉”、“安妮”、“奈吉”], lastNames=[“达沃利奥”、“富勒”、“勒沃林”、“孔雀”、“布坎南”、“苏亚玛”、“国王”、“卡拉汉”、“多兹沃思”、“怀特”], 城市=[“西雅图”、“塔

执行以下操作时,网格行为不符合预期

  • 添加新记录
  • 然后按网格中的更新按钮(新添加的行)
  • 然后在保存前按取消
  • 当上述操作完成时,新添加的行将消失。

    
    演示网格应用程序
    演示网格应用程序
    var firstNames=[“南希”、“安德鲁”、“珍妮特”、“玛格丽特”、“史蒂文”、“迈克尔”、“罗伯特”、“劳拉”、“安妮”、“奈吉”],
    lastNames=[“达沃利奥”、“富勒”、“勒沃林”、“孔雀”、“布坎南”、“苏亚玛”、“国王”、“卡拉汉”、“多兹沃思”、“怀特”],
    城市=[“西雅图”、“塔科马”、“科克兰”、“雷蒙德”、“伦敦”、“费城”、“纽约”、“西雅图”、“伦敦”、“波士顿”],
    职称=[“会计”、“销售副总裁”、“销售代表”、“技术支持”、“销售经理”、“网页设计师”,
    “软件开发人员”、“内部销售协调员”、“首席技术官”、“首席执行官”],
    生日=[新日期(“1948/12/08”)、新日期(“1952/02/19”)、新日期(“1963/08/30”)、新日期(“1937/09/19”)、新日期(“1955/03/04”)、新日期(“1963/07/02”)、新日期(“1960/05/29”)、新日期(“1958/01/09”)、新日期(“1966/01/27”)、新日期(“1966/03/27”);
    函数createRandomData(计数){
    var数据=[],
    现在=新日期();
    对于(变量i=0;i
    该行为是预期的。问题在于新创建的记录没有ID,这就是为什么它们被视为新记录。你可以用这个方法检查一下

    取消编辑新记录(尚未同步)时,该记录将被删除。操作与:按“添加新记录”a相同
    <!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 createRandomData(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: createRandomData(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,
                            filterable: 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>
    
            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();   
                }
            }