let arr=r.result.feedGmBackVOs;
时间: 2024-10-08 07:24:27 浏览: 39
在JavaScript中,`let arr = r.result.feedGmBackVOs;` 这行代码的作用是创建了一个新的局部变量`arr`,并将它的值设置为对象`r.result`中名为`feedGmBackVOs`的属性。这里的`r`很可能是一个函数返回的对象,或者是某个API、回调函数的结果,`feedGmBackVOs`可能是包含了多个反馈对象(比如对象数组)的数据集。
这句代码假设`r.result`是一个包含嵌套结构的对象,其中`feedGmBackVOs`字段指向的是另一个对象或数组。通过这个赋值,你现在可以直接通过`arr`来访问和操作这些反馈对象。
举个例子,如果`feedGmBackVOs`是一个数组:
```javascript
const r = { result: { feedGmBackVOs: [ { id: 1, name: 'Feedback 1' }, { id: 2, name: 'Feedback 2' } ] } };
let arr = r.result.feedGmBackVOs;
console.log(arr[0].name); // 输出 'Feedback 1'
```
相关问题
lifetimes: { attached() { let that = this let userPhoneStr = '' let userEmailStr = '' let peopleNameStr = '' let userPhone = '' let userPhoneInvoice = wx.getStorageSync('memberMsg').memberMobile userPhone = userPhoneInvoice let arr = userPhoneInvoice.split('') for (let x = 0; x < arr.length; x++) { if ((x >= 0 && x <= 2) || (x >= 7 && x < arr.length)) { userPhoneStr += arr[x] } else { userPhoneStr += '*' } } if (wx.getStorageSync('userEmailInvoice') != '') { userEmailStr = wx.getStorageSync('userEmailInvoice') } if (wx.getStorageSync('userNameInvoice') != '') { peopleNameStr = wx.getStorageSync('userNameInvoice') } this.setData({ userPhoneStr, userEmailStr, peopleNameStr, userPhone }) wx.getSystemInfo({ success: e => { that.setData({ pageHeight: e.windowHeight, invoiceModalMaxHeight: e.windowHeight * 0.6 }) if (that.data.isiPhoneX) { that.setData({ invoiceModalScrollMaxHeight: e.windowHeight * 0.6 - 120 }) } else { that.setData({ invoiceModalScrollMaxHeight: e.windowHeight * 0.6 - 90 }) } } }) } }, 改成uniapp
可以将该段代码转换为uni-app的语法:
```
export default {
onReady() {
let that = this;
let userPhoneStr = '';
let userEmailStr = '';
let peopleNameStr = '';
let userPhone = '';
let userPhoneInvoice = uni.getStorageSync('memberMsg').memberMobile;
userPhone = userPhoneInvoice;
let arr = userPhoneInvoice.split('');
for (let x = 0; x < arr.length; x++) {
if ((x >= 0 && x <= 2) || (x >= 7 && x < arr.length)) {
userPhoneStr += arr[x];
} else {
userPhoneStr += '*';
}
}
if (uni.getStorageSync('userEmailInvoice') != '') {
userEmailStr = uni.getStorageSync('userEmailInvoice');
}
if (uni.getStorageSync('userNameInvoice') != '') {
peopleNameStr = uni.getStorageSync('userNameInvoice');
}
this.setData({
userPhoneStr,
userEmailStr,
peopleNameStr,
userPhone
});
uni.getSystemInfo({
success: e => {
that.setData({
pageHeight: e.windowHeight,
invoiceModalMaxHeight: e.windowHeight * 0.6
});
if (that.data.isiPhoneX) {
that.setData({
invoiceModalScrollMaxHeight: e.windowHeight * 0.6 - 120
});
} else {
that.setData({
invoiceModalScrollMaxHeight: e.windowHeight * 0.6 - 90
});
}
}
});
}
}
```
注意,我将`attached`改为了`onReady`,因为在uni-app中没有`attached`这个生命周期函数。另外,我使用了`uni.`代替了`wx.`,因为uni-app是跨平台框架,需要使用uni-app提供的API。
function getCateList(cateId) { let arr = []; const filterCate = (id) => { productCateList({ id, siteType: '01', platformType: '01' }).then( (res) => { arr = [...res.data, ...arr]; if (res.data[0].parentId && res.data[0].parentId !== '0') { return filterCate(res.data[0].parentId); } else { return arr; } } ); }; return filterCate(cateId);} 修复
修改后的代码如下:
```javascript
function getCateList(cateId) {
let arr = [];
const filterCate = (id) => {
return productCateList({ id, siteType: '01', platformType: '01' }).then(
(res) => {
arr = [...res.data, ...arr];
if (res.data[0].parentId && res.data[0].parentId !== '0') {
return filterCate(res.data[0].parentId);
} else {
return arr;
}
}
);
};
return filterCate(cateId);
}
```
我添加了一个 `return` 语句,以便 `filterCate` 函数返回一个 Promise 对象,以便在获取完所有子分类后,通过 Promise 对象解析来获取结果。
阅读全文