我不确定这是因为来晚了还是什么,但是我今晚似乎很难度过思考,通过构造一个非常基本的对象数组并构建它。
我想做的是收集一个文本字段ID的列表,并将它们放入一个组变量中。
例子
groupA:{year, make, model}
groupB:{color,body}
我不确定如何构造我的主组对象。我不确定是否应该使用数组。下面是我的第一次尝试
group = {groupA:{"year","make","model","trim"},groupB:{"body","color","transmission"}}
我试图像这样构建我的组对象,但是我真的觉得自己做错了。
//Class variable
Var group = {}
//this method is called for every textfield
selectGroup = function(spec) {
//Group id is the group the field is assigned to, example groupA, or groupB
var groupId = spec.groupId;
//I'm checking to see if groupId exist in group object, otherwise I add it.
if (!group.hasOwnProperty(groupId)) {
var obj = {};
obj[groupId] = [];
group = obj;
}
//spec.id is the field id, example make, model
group[groupId].push(spec.id);
};
如果有人可以帮助我解决所有问题,我将不胜感激。提前致谢。
在这里,你去工作提琴
var group = {};
//this method is called for every textfield
selectGroup = function (spec) {
//Group id is the group the field is assigned to, example groupA, or groupB
var groupId = spec.groupId;
//I'm checking to see if groupId exist in group object, otherwise I add it.
if (!group.hasOwnProperty(groupId)) {
group[groupId] = [];
}
//spec.id is the field id, example make, model
group[groupId].push(spec.id);
};
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句