【发布时间】:2011-02-03 20:44:37
【问题描述】:
我有一个需要返回数组或对象的函数。我不确定哪个是最好的,也不知道如何构建它。这是我到目前为止所拥有的。密切关注所有大写字母中的 cmets。这个想法是遍历一组包含“数据字段”属性的 td 单元格,并使用属性的名称作为变量名和包含在 td 中的文本作为值。数组/对象的属性或值的数量是未知的。根据点击进入函数的内容,将需要 2-6 个值。
function InlineEditMode(rowID, entryType) {
// store current row data in case of cancel
var original = $('#'+rowID).contents();
// DEFINE SOME ARRAY OR OBJECT HERE
// put original values in the newEntry Array with a loop, using the
// data-field attributes as the name of the array or object variables
// and the text of the td as the value
$('#'+rowID+' td[data-field]').each(function() {
var field = $(this).attr('data-field');
var value = $(this).text();
// BUILD OUT OBJECT OR ARRAY
});
// RETURN ARRAY OR OBJECT
}
【问题讨论】:
-
听起来你需要一个哈希映射/关联数组