const arr = [{a:23,b:34},{a:123,b:134}]
console.log(arr)
for (let v of arr){
console.log(v)
const old = v.a
v.a=old*old
console.log(v)
}
console.log(arr)

arr已经发生了改变

场景

微信小程序开发

对后端接口的时间戳格式数据处理

\mpBMCwepy\src\utils\util.js

const timestampSecondsToTime = (tmp) => {
const t = function (i) {
return (i < 10 ? '0' + (i) : i)
}
const date = new Date(tmp * 1000)
const Y = date.getFullYear() + '-'
const M = t(date.getMonth() + 1) + '-'
const D = t(date.getDate()) + ' '
const h = t(date.getHours()) + ':'
const m = t(date.getMinutes()) + ':'
const s = t(date.getSeconds())
return Y + M + D + h + m + s
}
const convertArrObjListTimestamp = (arr, timestampKey) => {
for (let v of arr) {
const old = v[timestampKey]
v[timestampKey] = timestampSecondsToTime(old)
}
return arr
}
export default {
isInClosedInterval,
isLogined,
isMobilePhoneNum,
delAllNonPrintableCharacter,
convertArrObjListTimestamp
} mpBMCwepy\src\pages\cloundAd.vue async getFeedData() {
if (this.apiRes.AdKWPublished !== undefined) {
if (this.pagination.total === this.apiRes.AdKWPublished.length) {
wx.showToast({
title: '亲我有底线',
icon: 'loading',
duration: 1500
})
return
}
}
const q = {
query: {
uid: this.$parent.UID.uid,
page: this.pagination.from,
size: this.pagination.size
}
}
const r = await api.getAdKWPublished(q)
if (r === false) {
return
} else if (r.data.status !== 1) {
wx.showToast({
title: '亲暂无更多',
icon: 'loading',
duration: 1500
})
return
}
let arr = r.data.data
arr = util.convertArrObjListTimestamp(arr, 'create_time')
this.apiRes.AdKWPublished = this.apiRes.AdKWPublished ? this.apiRes.AdKWPublished.concat(arr) : arr
this.pagination.total = r.data.count
this.pagination.from += 1
this.$apply()
}

  

方法: 对可读的时间格式的多样性扩展性

暂时没有满足开闭原则

const a={
false :'123',
v:567
}
const b=false
a[b]

05-28 21:25