Bind to Normalized data

4 posts, 1 answers
  1. Dominik
    Dominik avatar
    28 posts
    Member since:
    May 2015

    Posted 29 Jul 2015 Link to this post

    how do you bind Data Source to normalized data?  I know I can take the fields and data2 arrays and construct something that looks like data1 but that will be time consuming.

     

    // Denormalized
    var data1 = [{"name":"John", "age":20},{"name":"Tom", "age":25}];
     
    // Normalized
    var fields = ["name","age"];
    var data2 = [["John",20],["Tom",25]];

  2. Answer
    Alexander Popov
    Admin
    Alexander Popov avatar
    1416 posts

    Posted 31 Jul 2015 Link to this post

    Hi Dominik,

    I am afraid this scenario is not supported, so constructing an array of objects similar to "data1" is the only available option.

    Regards,
    Alexander Popov
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  3. Kendo UI is VS 2017 Ready
  4. Dominik
    Dominik avatar
    28 posts
    Member since:
    May 2015

    Posted 31 Jul 2015 in reply to Alexander Popov Link to this post

    Thank you for your post. I finally figured that out but I left it open because someone might have this question in the future.

     However if you could answer this question it would be really helpful:

    http://www.telerik.com/forums/data-source---schema---parse-function-error-when-creating-new-function

    This question is related to this one. 

     

    // My starting Normalized data
    var fields = ["name","age"];
    var data2 = [["John",20],["Tom",25]];
     
     
    // What I want the result to look like Denormalized
    var data1 = [{"name":"John", "age":20},{"name":"Tom", "age":25}];
     
     
    // Solution 1 O(N^2) --- this is slow
     
    var fields = ["name","age"];
    var data2 = [["John",20],["Tom",25]];
    var data1 = [];
    for(var i = 0; i < data2.length; i++){
       var temp = {};
       for(var y = 0; y < fields.length; y++){
          temp[fields[y]] = data2[i][y];
       }
       data1.push(temp);
    }
     
     
    // solution 2 O(N)
     
    var fields = ["name","age"];
    var data2 = [["John",20],["Tom",25]];
    var body = "";
     
    for(var i = 0; i < fields.length; i++){
       body += "this."+fields[i] +"=args["+i+"]; ";
    }
     
    var model = new Function("args",body);
     
    var data1 = [];
    for(var i = 0; i < data2.length; i++){
       var x = new model(data2[i]);
       data1.push(x);
    }

     ​

  5. Alexander Popov
    Admin
    Alexander Popov avatar
    1416 posts

    Posted 04 Aug 2015 Link to this post

    Thanks for the follow up Dominik. I see that my colleague Vasil has already addressed the queries in the forum thread you mentioned.

    Regards,
    Alexander Popov
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
Back to Top
Kendo UI is VS 2017 Ready