array=[
{
createUser: ' '
numberOfPeriods: ''
pId: ' '
projectExpDetails: [
{
cId:
cName:
distributionProportion:
editable:
remarks:
transactionBudget:
unUsedBudget:
usedBudget:
},
{
cId:
cName:
distributionProportion:
editable:
remarks:
transactionBudget:
unUsedBudget:
usedBudget:
}
]
},
]
为数组array中projectExpDetails数组中的unUsedBudget字段赋值,
a为父下标,index子下标,col为动态字段
使用了:this.$set(this.array[a]['projectExpDetails'][index],col,value)赋值,使用this.array[a]['projectExpDetails'][index][col]=value,也是一样的效果
这样赋值把array下的每个projectExpDetails的unUsedBudget字段都赋值,
例:
array=[
{
createUser: ' '
numberOfPeriods: ' '
pId: ' '
projectExpDetails: [
{
cId:
cName:
distributionProportion:
editable:
remarks:
transactionBudget:
unUsedBudget: ‘赋的值’
usedBudget:
},
{
cId:
cName:
distributionProportion:
editable:
remarks:
transactionBudget:
unUsedBudget:
usedBudget:
}
]
},
{
createUser: ' '
numberOfPeriods: ' '
pId: ' '
projectExpDetails: [
{
cId:
cName:
distributionProportion:
editable:
remarks:
transactionBudget:
unUsedBudget: ‘赋的值’
usedBudget:
},
{
cId:
cName:
distributionProportion:
editable:
remarks:
transactionBudget:
unUsedBudget:
usedBudget:
}
]
},
{
createUser: ' '
numberOfPeriods: ' '
pId: ' '
projectExpDetails: [
{
cId:
cName:
distributionProportion:
editable:
remarks:
transactionBudget:
unUsedBudget: ‘赋的值’
usedBudget:
},
{
cId:
cName:
distributionProportion:
editable:
remarks:
transactionBudget:
unUsedBudget:
usedBudget:
}
]
},
{
createUser: ''
numberOfPeriods: ''
pId: ' '
projectExpDetails: [
{
cId:
cName:
distributionProportion:
editable:
remarks:
transactionBudget:
unUsedBudget: ‘赋的值’
usedBudget:
},
{
cId:
cName:
distributionProportion:
editable:
remarks:
transactionBudget:
unUsedBudget:
usedBudget:
}
]
},
]
求,赋值相应下标的的字段的值
![](https://profile-avatar.csdnimg.cn/eb4d852707034e39b127bc792b305951_weixin_45325148.jpg!4)
vue中多层数组 赋值出错
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
2条回答 默认 最新
关注
this.$set(this.array[a]['projectExpDetails'][index],col,value)修改我这边是正常的
<template> <div class="app-container"> <div v-for="(item, index) in array" :key="index"> {{ item.projectExpDetails[1].unUsedBudget }} </div> </div> </template> <script> export default { name: "test", components: {}, data() { return { obj: { "01": "1111", "02": "222", "03": "33333", 10: "44444", 加班: "", }, array: [ { createUser: " ", numberOfPeriods: "", pId: " ", projectExpDetails: [ { cId: "", cName: "", distributionProportion: "", editable: "", remarks: "", transactionBudget: "", unUsedBudget: "1", usedBudget: "", }, { cId: "", cName: "", distributionProportion: "", editable: "", remarks: "", transactionBudget: "", unUsedBudget: "1", usedBudget: "", }, ], }, { createUser: " ", numberOfPeriods: "", pId: " ", projectExpDetails: [ { cId: "", cName: "", distributionProportion: "", editable: "", remarks: "", transactionBudget: "", unUsedBudget: "2", usedBudget: "", }, { cId: "", cName: "", distributionProportion: "", editable: "", remarks: "", transactionBudget: "", unUsedBudget: "2", usedBudget: "", }, ], }, { createUser: " ", numberOfPeriods: "", pId: " ", projectExpDetails: [ { cId: "", cName: "", distributionProportion: "", editable: "", remarks: "", transactionBudget: "", unUsedBudget: "3", usedBudget: "", }, { cId: "", cName: "", distributionProportion: "", editable: "", remarks: "", transactionBudget: "", unUsedBudget: "3", usedBudget: "", }, ], }, ], }; }, created() { this.setM(1,1,"unUsedBudget","test修改") console.log(JSON.stringify(this.array, null, " ")); }, methods: { setM(a, index, col, value) { this.$set(this.array[a]['projectExpDetails'][index],col,value) } }, }; </script>
解决 无用评论 打赏 举报
悬赏问题
- ¥15 keil+mspm0g3507+二维总线舵机
- ¥15 如何用wireshark分析找出url接口和param参数
- ¥15 有谁知道这是阿里云那个应用的域名吗,怎么调用?
- ¥30 正则表达式的一些问题
- ¥15 C#如何使用ClosedXML库搭配别的库实现:将指定Excel区域导出为图片(例如A1:AO50)
- ¥15 虚拟机只能接收不能发送
- ¥15 为什么echarts极坐标柱形图的图形显示的特别小呢
- ¥20 网络科学导论,网络同步与控制
- ¥50 arcpy将数据库要素类添加到图层组以及创建要素收藏夹如何创建文件夹并将模板中的符号添加到文件夹中
- ¥15 我的住宅ip和vps的地址都是法国 可是在whoer里面一直查询我的位置是美国 这种ip不符合是什么问题导致的 怎么解决 手机电脑换电脑用whoer查询都是美国 用别的查询都是在法国