gpt4 book ai didi

Jquery 每个函数中的每个返回未定义

转载 作者:行者123 更新时间:2023-12-01 06:23:17 27 4
gpt4 key购买 nike

我正在使用 $.each 函数循环一个对象,但我得到的是不确定的值。

我的代码有什么问题吗?

var mainPageCircle = {
circles: {
c1: {
color: '#730000',
text: 'Content'
},
c2: {
color: '#004f74',
text: 'Consulting'
},
c3: {
color: '#146c00',
text: 'Commerce'
}
},
radious: 100,
stroke: 10,
strokeColor: '#fff',
opacity: 0.7
}

$.each(mainPageCircle, function(key, value) {
var circles = value.circles,
radious = value.radious;
$.each(circles, function(index, c) {
console.log(index, c); // i am getting error; i need index should be 0,1,2 and c should be : c1,c2,c3 values
})
})

最佳答案

您的each正在针对mainPageCircle的所有项目运行,而不仅仅是其中定义的圆圈。这可能更符合您的目标:

var mainPageCircle = {
circles :{
c1:{color:'#730000',text:'Content'},
c2:{color:'#004f74',text:'Consulting'},
c3:{color:'#146c00',text:'Commerce'}
},
radious:100,
stroke:10,
strokeColor:'#fff',
opacity:0.7
}
$.each(mainPageCircle.circles , function (key,value) {
var circles = value,radious = mainPageCircle.radious;
$.each(circles, function (index,c) {
console.log(index,c);
});
});

关于Jquery 每个函数中的每个返回未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13247523/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com