I have this example array for an entry to be inserted to a YUI datatable
var book = {
"id" : "po-0167",
"date" : new Date(1980, 2, 24),
"quantity" : 1,
"amount" : 4,
"title" : "A Book About Nothing"
};
will i be able to 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 am trying here is to write a generic method that will iterate through a list of results and able to form an entry 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 could i make the array the same as the first segment of the book code?
added my whole sample code, the commented book array seems to work but the uncommented part seems to not be able to show the rows
<script type="text/javascript">
YAHOO.util.Event.addListener(window, "load", function() {
YAHOO.example.Data = {
bookorders: [
]
}
var bookorders = [];
/*
var book = {
"id" : "po-0167",
"date" : new Date(1980, 2, 24),
"quantity" : 1,
"amount" : 4,
"title" : "A Book About Nothing"
};
*/
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
};
}();
});