This is a migrated thread and some comments may be shown as answers.

Bind to Normalized data

3 Answers 46 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Dominik
Top achievements
Rank 1
Dominik asked on 29 Jul 2015, 03:26 PM

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]];

3 Answers, 1 is accepted

Sort by
0
Accepted
Alexander Popov
Telerik team
answered on 31 Jul 2015, 07:44 AM
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!
 
0
Dominik
Top achievements
Rank 1
answered on 31 Jul 2015, 01:26 PM

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);
}

 ‚Äč

0
Alexander Popov
Telerik team
answered on 04 Aug 2015, 08:12 AM
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!
 
Tags
Data Source
Asked by
Dominik
Top achievements
Rank 1
Answers by
Alexander Popov
Telerik team
Dominik
Top achievements
Rank 1
Share this question
or