当前位置: 代码迷 >> JavaScript >> kendo ui数据源-架构-在内部创建新函数时解析函数错误
  详细解决方案

kendo ui数据源-架构-在内部创建新函数时解析函数错误

热度:92   发布时间:2023-06-05 14:13:42.0

我正在使用以下构造函数创建一个新函数: new Function("args", body);

但是在解析函数中,它将引发以下错误:

Uncaught SyntaxError: Unexpected identifierkendo.data.DataSource.schema.parse @ KendoWorklist?processId=1:257g.extend.success @ kendo?v=eOyB53xLlSdFHOrBbggvVxenL4FmfrA-viibHS3DbGs1:1g.extend.read.i._queueRequest.i.online.i.transport.read.success @ kendo?v=eOyB53xLlSdFHOrBbggvVxenL4FmfrA-viibHS3DbGs1:1vt.extend.read.i.success @ kendo?v=eOyB53xLlSdFHOrBbggvVxenL4FmfrA-viibHS3DbGs1:1i.Callbacks.a @ jquery?v=FVs3ACwOLIVInrAl5sdzR2jrCDmVOWFbZMY6g6Q0ulE1:1i.Callbacks.h.fireWith @ jquery?v=FVs3ACwOLIVInrAl5sdzR2jrCDmVOWFbZMY6g6Q0ulE1:1k @ jquery?v=FVs3ACwOLIVInrAl5sdzR2jrCDmVOWFbZMY6g6Q0ulE1:1i.ajaxTransport.send.u @ jquery?v=FVs3ACwOLIVInrAl5sdzR2jrCDmVOWFbZMY6g6Q0ulE1:1

为什么新的Function构造函数不能在parse函数中工作?

如果使模型超出架构的解析功能,则可以像这样使用它

   <script>
      var fields = ["fieldA","fieldB"];
      var body = "";

    for(var i = 0; i < fields.length; i++){
       body += "this."+fields[i] +"=args["+i+"]; ";
    }
      var model = new Function("args",body);

    var dataSource = new kendo.data.DataSource({
      transport: {
        read: {
          url: "", //your url
          dataType: "jsonp"
        }
      },
      schema: {
        parse: function(response) {  
         var parsedresponse = [];    
          for (var i = 0; i < response.length; i++) {
             var x = new model(response[i]);   
             parsedresponse .push(prxduct);
          }

          return parsedresponse;
        }
      }
    });

    </script>