Vue动态绑定属性和动态获取属性值

     基本不用写前端了,虽然Vue不太会,Jquery还是会点的,Jquery可以动态绑定设定值,作为Vue这么牛逼优秀的框架,会不支持动态绑定?我今天快被合作的前端小哥给气到了,不行必须得写出来,太气人了,做后端的帮你搞定下。想要个Json数据咋就这么困难呢。

大致需求:

原数据:

{
  grade1:1
  grade2:2
  grade3:3
  level1:1
  level2:2
  level3:3
  gradeId1:1
  gradeId2:2
  gradeId3:3
   
}
想得到的数据
[
 {
   grade1:1,
   level1:1,
   gradeId2:3
 },
 {
   grade2:2,
   level2:2,
   gradeId2:3
 },
 {
   grade3:3,
   level3:3,
   gradeId3:3
 }
]

代码:

let newList = []
let pageObj = {
  level2: 2,
  grade6: 8831,
  grade5: 8374,
  levelName: '二',
  gradeId1: '20001',
  grade4: 7917,
  grade3: 7460,
  grade2: 7003,
  grade1: 6546,
  level1: 1,
  level3: 3,
  level4: 4,
  gradeId7: '20007',
  gradeId6: '20006',
  gradeId3: '20003',
  gradeId2: '20002',
  gradeId5: '20005',
  gradeId4: '20004',
  grade7: 9288,

  gradeSize: 7
}
for (let i = 1; i <= pageObj.gradeSize; i++) {
  let obj = {}
  debugger
  this.$set(obj, 'grade' + i, pageObj['grade1'])
  this.$set(obj, 'level' + i, pageObj['level' + i])
  this.$set(obj, 'gradeId' + i, pageObj['gradeId' + i])
  newList.push(obj)
}
console.log(newList, '11111')
let postForm = []
for (let i = 1; i <= pageObj.gradeSize; i++) {
  let obj = {}
  this.$set(obj, 'grade', pageObj['grade' + i])
  this.$set(obj, 'level', pageObj['grade' + i])
  this.$set(obj, 'gradeId', pageObj['gradeId' + i])
  postForm.push(obj)
}
console.log(postForm, '222222')

结果:

Vue动态绑定属性和动态获取属性值_第1张图片

 

 

 

你可能感兴趣的:(笔记,vue)