更新时出现Kendo Grid错误 - 没有数据库问题

时间:2014-08-14 10:23:09

标签: kendo-ui kendo-grid

每次更新任何行时都会出现此错误。 更新本身在数据库中是成功的,但是当我触发kendo的成功方法时,它似乎很困扰,在开始时我认为可能是我从数据库返回的对象是不同的,但它与我提交的那个。 提前致谢

Uncaught SyntaxError: Unexpected identifier 
yt.setter 
lt.extend._set 
Ut.extend.accept  
lt.extend._accept  
(anonymous function) 
(anonymous function) 
j  
k.fireWith  
e.(anonymous function)  
o.(anonymous
function).call.X.success 
$.ajax.success  
j 
k.fireWith  
x 
b

以下是代码:

        dataSource = new kendo.data.DataSource({
            transport: {
                read: function(options) {
                    $.ajax( {
                        url: crudServiceBaseUrl + "?serviceType=students&serviceFunction=getStudentLists&type=2",
                        dataType: "json",
                        success: function(result) {
                            var data = _.flatten(result);
                            options.success(data);
                        }
                    });
                },
                update: function(options) {
                    $.ajax( {
                        type: 'POST',
                        url: "/tools.php?id=ajaxstudentlist",
                        dataType: "json",
                        data: {data:options.data.models},
                        success: function(result) {
                            var arr = [];
                            arr.push(result);
                            var data = _.flatten(arr);
                            options.success();
                        }
                    });
                },
                parameterMap: function(options, operation) {
                    if (operation !== "read" && options.models) {
                        return {models: kendo.stringify(options.models)};
                    }
                }
            },
            batch: true,
            pageSize: 70,
            schema: {
                model: {
                    id: "studystatusid",
                    fields: {
                        studystatusid : { type: 'number', editable: false, nullable: true },
                        studentid : { type: 'string', editable: false, nullable: false},
                        lastname : { type: 'string', editable: false, },
                        firstname : { type: 'string', editable: false, },
                        spnumber : { type: 'string', editable: false, },
                        status : { type: 'string', editable: false, },
                        begin_date: { type: "date", validation: { required: true } },
                        end_date: { type: "date" }
                    }
                },
                parse : function(data) {
                    for (var i = data.length - 1; i >= 0; i--) {
                        data[i].studentid = addZeros(data[i].studentid);
                        if(data[i].begin_date !== '0'){
                            data[i].begin_date = new Date(parseInt(data[i].begin_date+ '000'));
                        }
                        if(data[i].end_date){
                            data[i].end_date = new Date(parseInt(data[i].end_date+ '000'));
                        }
                    }
                    return data;
                }
            }
        });

2 个答案:

答案 0 :(得分:0)

你为什么要在剑道内调用ajax?

应该像下面的代码一样。试试这个并更新状态,如果没有成功,我将修改代码。

dataSource = new kendo.data.DataSource({
    transport: {
        read:  {
            url: crudServiceBaseUrl + "?serviceType=students&serviceFunction=getStudentLists&type=2",
            dataType: "json",
            success: function (data) {
               console.log(data);
            }
        },
     update: {
           url: "/tools.php?id=ajaxstudentlist",
           dataType: "json",
           data:{inputParam:inputvalue},
           success: function(result) {
             console.log(data);
           }
     },
    parameterMap: function(options, operation) {
        if (operation !== "read" && options.models) {
           return {models: kendo.stringify(options.models)};
         }
       }
    },
   batch: true,
   pageSize: 20,
   schema: {
      model: {
           id: "studystatusid",
           fields: {
                studystatusid : { type: 'number', editable: false, nullable: true },
                studentid : { type: 'string', editable: false, nullable: false},
                lastname : { type: 'string', editable: false, },
                firstname : { type: 'string', editable: false, },
                spnumber : { type: 'string', editable: false, },
                status : { type: 'string', editable: false, },
                begin_date: { type: "date", validation: { required: true } },
                end_date: { type: "date" }
                }
            }
     }
}); 

答案 1 :(得分:0)

您的数据源更新

 update: function(options) {
                    $.ajax( {
                        type: 'POST',
                        url: "/tools.php?id=ajaxstudentlist",
                        dataType: "json",
                        data: {data:options.data.models},
                        success: function(result) {
                            var arr = [];
                            arr.push(result);
                            var data = _.flatten(arr);
                            options.success();
                        }
                    });
                },

上面的ajax调用期待JSON结果返回,你应该返回一个JSON结果为成功,它更好地返回更新的行。