我有脚本在选择框中显示下拉列表。我当前正在使用的脚本是
jQuery.each( dslr, function( index, dslrgp) {
var aslrp= dslrgp.aslrp;
jQuery.each( aslrp, function(index2, pslrp) {
var found = 0;
jQuery.each( dropdown, function(index3, dditem) {
if (dditem.countryname == pslrp.countryname)
{
foundit = 1;
}
});
if (foundit == 0)
dropdown.push(pslrp);
});
});
我如何将其转换为纯JavaScript。因为如果我用这个
dslr.forEach(function( index, dslrgp) {
var aslrp= dslrgp.aslrp;
aslrp.forEach(function(index2, pslrp) {
var found = 0;
dropdown.forEach(function(index3, dditem) {
if (dditem.countryname == pslrp.countryname)
{
foundit = 1;
}
});
if (foundit == 0)
dropdown.push(pslrp);
});
});
它不起作用。
请注意,native参数的顺序不同forEach
-第一个是item的值,第二个是index。因此,而不是:
aslrp.forEach(function(index2, pslrp) {
...
dropdown.forEach(function(index3, dditem) {
用这个:
aslrp.forEach(function(pslrp, index2) {
...
dropdown.forEach(function(dditem,index3) {
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句