我有一个示例数组,用于插入到YUI数据表中
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);
我正在尝试编写一个通用方法,该方法将遍历结果列表并能够在未来形成一个条目。
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);
}
那么我该如何使数组与代码书第一个段落相同?
添加了整个样例代码,注释的 book 数组似乎工作正常,但未注释部分无法显示行。
<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
};
}();
});
for(var key in book){ var bookKey = key; var bookValue = obj[key]; }
- Ilya