Get field of C# list of struct from code behind in Javascript -


i access list<records> records struct, js script. after bit of googling (especially question 29098558 here) json serialized object , retrieve in script.

i should mention it's first time @ js syntax may totally wrong.

in c#

  string serializedresults = jsonconvert.serializeobject(recordslist); 

(in context records in dictionnary<string, records> hide access through dictionnary because supposed isn't relevant here)

in javascript

<script type="text/javascript">     function setupbarchart() {         var x = [];         var y = [];         var source = "<%= serializedrecords %>";          // put records fields in y , x tab use data axes of histogram.         (var = 0; < source.length; i++) {          }       } </script> 

my questions :

  • what type of source ? string ? create equivalent of list in js ?
  • how access records fields js ?
  • does source.length gives me number of records in list ??

what type of source ? string ? create equivalent of list in js ?

in code shown, string, think code shown wrong - quotes incorrect , should removed, to:

var source = <%= serializedrecords %>; 

(note, i'm not going opine on encoding in above, but: careful , check safe)

leaving (in rendered html):

var source = [{"foo":123,"bar":"def"},{...},{...}]; 

now type javascript array.

how access records fields js ?

via source, array

does source.length gives me number of records in list ??

yes, if lose quotes


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -