0

I am using the following constructor create a new function: new Function("args", body);

but in parse function it throwing the following error:

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

why would the new Function constructor not working in the parse function?

4
  • I'm lost with the question, what are you trying to do? can you give us more details Commented Jul 31, 2015 at 4:19
  • @cycopepe I'm trying to create a new function in the parse method like.... parse: function(response){ var x = new Function("args", body)} Commented Jul 31, 2015 at 4:34
  • @t-holland what is the reason to try to do that? Commented Jul 31, 2015 at 4:53
  • @cycopepe stackoverflow.com/questions/31707085/… look at my answer to this question. I'm parsing normalized data to become denormalized. Commented Jul 31, 2015 at 13:11

1 Answer 1

1

If make the model outside the parse function of the schema, you can use it like this

   <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>
Sign up to request clarification or add additional context in comments.

2 Comments

thank you! but I get the fields from the response object. I would have to call the data twice. I want to avoid it if possible but it may be the only way I'm really stumped.
actually I think I will just get the fields in a separate request like your answer suggests... the request will be small because I don't need any rows.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.