问题描述
我正在使用以下构造函数创建一个新函数: 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函数中工作?
1楼
cycopepe
1
已采纳
2015-07-31 15:00:17
如果使模型超出架构的解析功能,则可以像这样使用它
<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>