Note that there are some explanatory texts on larger screens.

plurals
  1. POPushing data into json array
    primarykey
    data
    text
    <p>i am trying to use the YUI to display a table. Using the following example</p> <pre><code>YAHOO.example.Data = { bookorders: [ {id:"po-0167", date:new Date(1980, 2, 24), quantity:1, amount:4, title:"A Book About Nothing"}, {id:"po-0783", date:new Date("January 3, 1983"), quantity:null, amount:12.12345, title:"The Meaning of Life"}, {id:"po-0297", date:new Date(1978, 11, 12), quantity:12, amount:1.25, title:"This Book Was Meant to Be Read Aloud"}, {id:"po-1482", date:new Date("March 11, 1985"), quantity:6, amount:3.5, title:"Read Me Twice"} ] } YAHOO.example.Basic = function() { var myColumnDefs = [ {key:"id", sortable:true, resizeable:true}, {key:"date", formatter:YAHOO.widget.DataTable.formatDate, sortable:true, sortOptions:{defaultDir:YAHOO.widget.DataTable.CLASS_DESC},resizeable:true}, {key:"quantity", formatter:YAHOO.widget.DataTable.formatNumber, sortable:true, resizeable:true}, {key:"amount", formatter:YAHOO.widget.DataTable.formatCurrency, sortable:true, resizeable:true}, {key:"title", sortable:true, resizeable:true} ]; var myDataSource = new YAHOO.util.DataSource(YAHOO.example.Data.bookorders); myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY; myDataSource.responseSchema = { fields: ["id","date","quantity","amount","title"] }; var myDataTable = new YAHOO.widget.DataTable("basic", myColumnDefs, myDataSource, {caption:"DataTable Caption"}); return { oDS: myDataSource, oDT: myDataTable }; }(); </code></pre> <p>but instead of using the bookorders Data, I queried a result from the database using a esri.tasks.QueryTask</p> <p>so i got to iterate through the data i got to populate the bookorders json array.</p> <pre><code>for (var i=0, il=results_books.features.length; i&lt;il; i++) { var featureAttributes = results_books.features[i].attributes; var string = " id : \"" + results_books.features[i].attributes[0] + "\","; var string = string + " date : \"" + results_books.features[i].attributes[1] + "\","; var string = string + " quantity: \"" + results_books.features[i].attributes[2] + "\","; var string = string + " amount: \"" + results_books.features[i].attributes[3] + "\","; var string = string + " title: \"" + results_books.features[i].attributes[4] + "\""; } </code></pre> <p>but how do i push the string into the JSON array and is the way to read the attributes correct?</p> <p><strong>EDIT</strong>: added the commas to the string</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload