给出下面的对象数组:
function person(first, last, RPI, o, t, u) {
this.first = first;
this.last = last;
this.RPI = RPI;
this.o = o;
this.t = t;
this.u = u;
}
var MD = new person('Mike', 'D', 1234, '', '', '');
var AY = new person('Adam', 'Y', 5678, '', '', '');
var AH = new person('Adam', 'H', 1212, '', '', '');
var personArray = new Array(MD, AY, AH);
如何将每个对象的RPI值迭代到此公式中?
function selector(x){
//do something with x.RPI
}
我试过了:
$.each(personArray , selector (personArray[person].RPI){
selector(x)
});
但它不起作用。我的每个陈述我做错了什么?
答案 0 :(得分:1)
$.each
回调需要是一个函数
做类似以下的事情:
var personArray = new Array (MW, MT, DR)
$.each(personArray, function(index, person){
console.log(person.RPI);
}
答案 1 :(得分:0)
将$ .each更改为
$.each(personArray , selector);
然后
function selector(index, item){
//do something with item.RPI
}