For Loop current item dot notation 不起作用
For Loop current item dot notation not working
美好的一天,有人可以帮我解决我在这里遇到的问题吗,我有一个对象数组的 for 循环,我可以使用带有括号表示法的数组名称访问 for 循环中的当前对象,并且然后通过在最后添加点符号来获得对象键。但是,当我尝试在 for 循环内访问 Axios 请求中的相同值时,它说无法访问未定义的键;
查看下面的代码查看 Axios 请求的 URL 值
var branches = [{"Key":"QXdpYWthbmRhIEZvb2Rz","Name":"Awiakanda Foods"},{"Key":"VldDIExPR0lTVElDUw","Name":"VWC LOGISTICS"},{"Key":"RXllbWFzdGVycyBMaW1pdGVkIC0gRmVzdGFj","Name":"Eyemasters Limited - Festac"}];
for (let i = 0; i <= this.branches.length; i++) {
var branch = this.branches[i];
console.log(branches[i].Key); //logs the key correctly but the axios request below cannot find Key
await this.$axios({
method: "GET",
url: `${apiBase + branch.Key}/${clientUrl + apiRoot}`,
headers,
})
.then(async (result) => {
if (this.branch.Name === "Awiakanda Foods") {
await this.$store.dispatch("awiakanda/updateLinks", result.data);
}})
.catch((err) => {
console.log(err);
});
}
您正在尝试访问不存在的 branches[length] 元素。不要尝试访问绑定元素之外的数组。
我 < array.length
正确方法如下:
var branches = [{"Key":"QXdpYWthbmRhIEZvb2Rz","Name":"Awiakanda Foods"},{"Key":"VldDIExPR0lTVElDUw","Name":"VWC LOGISTICS"},{"Key":"RXllbWFzdGVycyBMaW1pdGVkIC0gRmVzdGFj","Name":"Eyemasters Limited - Festac"}];
for (let i = 0; i < this.branches.length; i++) {
var branch = this.branches[i];
console.log(branch);
console.log(branches[i].Key);
console.log(branch.Key);
}
美好的一天,有人可以帮我解决我在这里遇到的问题吗,我有一个对象数组的 for 循环,我可以使用带有括号表示法的数组名称访问 for 循环中的当前对象,并且然后通过在最后添加点符号来获得对象键。但是,当我尝试在 for 循环内访问 Axios 请求中的相同值时,它说无法访问未定义的键;
查看下面的代码查看 Axios 请求的 URL 值
var branches = [{"Key":"QXdpYWthbmRhIEZvb2Rz","Name":"Awiakanda Foods"},{"Key":"VldDIExPR0lTVElDUw","Name":"VWC LOGISTICS"},{"Key":"RXllbWFzdGVycyBMaW1pdGVkIC0gRmVzdGFj","Name":"Eyemasters Limited - Festac"}];
for (let i = 0; i <= this.branches.length; i++) {
var branch = this.branches[i];
console.log(branches[i].Key); //logs the key correctly but the axios request below cannot find Key
await this.$axios({
method: "GET",
url: `${apiBase + branch.Key}/${clientUrl + apiRoot}`,
headers,
})
.then(async (result) => {
if (this.branch.Name === "Awiakanda Foods") {
await this.$store.dispatch("awiakanda/updateLinks", result.data);
}})
.catch((err) => {
console.log(err);
});
}
您正在尝试访问不存在的 branches[length] 元素。不要尝试访问绑定元素之外的数组。 我 < array.length 正确方法如下:
var branches = [{"Key":"QXdpYWthbmRhIEZvb2Rz","Name":"Awiakanda Foods"},{"Key":"VldDIExPR0lTVElDUw","Name":"VWC LOGISTICS"},{"Key":"RXllbWFzdGVycyBMaW1pdGVkIC0gRmVzdGFj","Name":"Eyemasters Limited - Festac"}];
for (let i = 0; i < this.branches.length; i++) {
var branch = this.branches[i];
console.log(branch);
console.log(branches[i].Key);
console.log(branch.Key);
}