Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

I would like to access a List<Records> where Records is a struct, from a JS script. After a bit of googling (especially question 29098558question 29098558 here) i Json serialized my object and retrieve it in the script.

I should mention it's my first time at JS so syntax may be totally wrong.

In C#

  string serializedResults = JsonConvert.SerializeObject(RecordsList);

(in my context the records are actually in a Dictionnary<string, Records> but i hide the access through dictionnary because i supposed it isn't relevant here)

In Javascript

<script type="text/javascript">
    function setupBarChart() {
        var x = [];
        var y = [];
        var source = "<%= serializedRecords %>";

        // I would like to put Records fields in y and x tab to use it as data for the axes of an histogram.
        for (var i = 0; i < source.length; i++) {
       
        }  
    }
</script>

My questions are :

  • what is the type of source ? Is it just a string ? Does it create an equivalent of List in JS ?
  • How do I access my Records fields from JS ?
  • Does source.length gives me the number of records in the list ??

I would like to access a List<Records> where Records is a struct, from a JS script. After a bit of googling (especially question 29098558 here) i Json serialized my object and retrieve it in the script.

I should mention it's my first time at JS so syntax may be totally wrong.

In C#

  string serializedResults = JsonConvert.SerializeObject(RecordsList);

(in my context the records are actually in a Dictionnary<string, Records> but i hide the access through dictionnary because i supposed it isn't relevant here)

In Javascript

<script type="text/javascript">
    function setupBarChart() {
        var x = [];
        var y = [];
        var source = "<%= serializedRecords %>";

        // I would like to put Records fields in y and x tab to use it as data for the axes of an histogram.
        for (var i = 0; i < source.length; i++) {
       
        }  
    }
</script>

My questions are :

  • what is the type of source ? Is it just a string ? Does it create an equivalent of List in JS ?
  • How do I access my Records fields from JS ?
  • Does source.length gives me the number of records in the list ??

I would like to access a List<Records> where Records is a struct, from a JS script. After a bit of googling (especially question 29098558 here) i Json serialized my object and retrieve it in the script.

I should mention it's my first time at JS so syntax may be totally wrong.

In C#

  string serializedResults = JsonConvert.SerializeObject(RecordsList);

(in my context the records are actually in a Dictionnary<string, Records> but i hide the access through dictionnary because i supposed it isn't relevant here)

In Javascript

<script type="text/javascript">
    function setupBarChart() {
        var x = [];
        var y = [];
        var source = "<%= serializedRecords %>";

        // I would like to put Records fields in y and x tab to use it as data for the axes of an histogram.
        for (var i = 0; i < source.length; i++) {
       
        }  
    }
</script>

My questions are :

  • what is the type of source ? Is it just a string ? Does it create an equivalent of List in JS ?
  • How do I access my Records fields from JS ?
  • Does source.length gives me the number of records in the list ??
added 2 characters in body
Source Link
Ythio Csi
  • 387
  • 2
  • 15

I would like to access a List<Records> where Records is a struct, from a JS script. After a bit of googling (especially question 29098558 here) i Json serialized my object and retrieve it in the script.

I should mention it's my first time at JS so syntax may be totally wrong.

In C#

  string serializedResults = JsonConvert.SerializeObject(RecordsList);

(in my context the records are actually in a Dictionnary<string, Records>Dictionnary<string, Records> but i hide the access through dictionnary because i supposed it isn't relevant here)

In Javascript

<script type="text/javascript">
    function setupBarChart() {
        var x = [];
        var y = [];
        var source = "<%= serializedRecords %>";

        // I would like to put Records fields in y and x tab to use it as data for the axes of an histogram.
        for (var i = 0; i < source.length; i++) {
       
        }  
    }
</script>

My questions are :

  • what is the type of source ? Is it just a string ? Does it create an equivalent of List in JS ?
  • How do I access my Records fields from JS ?
  • Does source.length gives me the number of records in the list ??

I would like to access a List<Records> where Records is a struct, from a JS script. After a bit of googling (especially question 29098558 here) i Json serialized my object and retrieve it in the script.

In C#

  string serializedResults = JsonConvert.SerializeObject(RecordsList);

(in my context the records are actually in a Dictionnary<string, Records> but i hide the access through dictionnary because i supposed it isn't relevant here)

In Javascript

<script type="text/javascript">
    function setupBarChart() {
        var x = [];
        var y = [];
        var source = "<%= serializedRecords %>";

        // I would like to put Records fields in y and x tab to use it as data for the axes of an histogram.
        for (var i = 0; i < source.length; i++) {
       
        }  
    }
</script>

My questions are :

  • what is the type of source ? Is it just a string ? Does it create an equivalent of List in JS ?
  • How do I access my Records fields from JS ?
  • Does source.length gives me the number of records in the list ??

I would like to access a List<Records> where Records is a struct, from a JS script. After a bit of googling (especially question 29098558 here) i Json serialized my object and retrieve it in the script.

I should mention it's my first time at JS so syntax may be totally wrong.

In C#

  string serializedResults = JsonConvert.SerializeObject(RecordsList);

(in my context the records are actually in a Dictionnary<string, Records> but i hide the access through dictionnary because i supposed it isn't relevant here)

In Javascript

<script type="text/javascript">
    function setupBarChart() {
        var x = [];
        var y = [];
        var source = "<%= serializedRecords %>";

        // I would like to put Records fields in y and x tab to use it as data for the axes of an histogram.
        for (var i = 0; i < source.length; i++) {
       
        }  
    }
</script>

My questions are :

  • what is the type of source ? Is it just a string ? Does it create an equivalent of List in JS ?
  • How do I access my Records fields from JS ?
  • Does source.length gives me the number of records in the list ??
Source Link
Ythio Csi
  • 387
  • 2
  • 15

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

I would like to access a List<Records> where Records is a struct, from a JS script. After a bit of googling (especially question 29098558 here) i Json serialized my object and retrieve it in the script.

In C#

  string serializedResults = JsonConvert.SerializeObject(RecordsList);

(in my context the records are actually in a Dictionnary<string, Records> but i hide the access through dictionnary because i supposed it isn't relevant here)

In Javascript

<script type="text/javascript">
    function setupBarChart() {
        var x = [];
        var y = [];
        var source = "<%= serializedRecords %>";

        // I would like to put Records fields in y and x tab to use it as data for the axes of an histogram.
        for (var i = 0; i < source.length; i++) {
       
        }  
    }
</script>

My questions are :

  • what is the type of source ? Is it just a string ? Does it create an equivalent of List in JS ?
  • How do I access my Records fields from JS ?
  • Does source.length gives me the number of records in the list ??