I have this example array for a record that needs to be inserted into a YUI datatable
var book = { "id" : "po-0167", "date" : new Date(1980, 2, 24), "quantity" : 1, "amount" : 4, "title" : "A Book About Nothing" };
can i get the same array by doing this?
var book = []; var booktemp = { "id" : "po-0167" }; book.push(booktemp); booktemp = { "date" : new Date(1980, 2, 24) }; book.push(booktemp); booktemp = { "quantity" : 1 }; book.push(booktemp); booktemp = { "amount" : 4 }; book.push(booktemp); booktemp = { "title" : "A Book About Nothing" }; book.push(booktemp);
what I'm trying here is to write a general method that will iterate over a list of results and be able to form a record in the future.
var resultsArray = []; for( int i = 0; i < array.features.length; i ++) { var resultsFeatureArray = []; for( att in array.features[i].attributes) { var temp = { att : array.features[i].attributes[att] } resultsFeatureArray.push(temp); } resultsArray.push(resultsFeatureArray); }
so how can i make the array the same as the first segment of the book code?
added my entire code sample, the comment array works, but the part without commenting, it seems, will not be able to show the lines
<script type="text/javascript"> YAHOO.util.Event.addListener(window, "load", function() { YAHOO.example.Data = { bookorders: [ ] } var bookorders = []; var book = []; var booktemp = { "id" : "po-0167" }; book.push(booktemp); booktemp = { "date" : new Date(1980, 2, 24) }; book.push(booktemp); booktemp = { "quantity" : 1 }; book.push(booktemp); booktemp = { "amount" : 4 }; book.push(booktemp); booktemp = { "title" : "A Book About Nothing" }; book.push(booktemp); bookorders.push(book); 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(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); return { oDS: myDataSource, oDT: myDataTable }; }(); });