javascript - 如何创建表单格式的json数组vuejs?
问题描述
我想问一下,我已经以单选按钮的形式在表格中输入了数据,之前我有我解析成表格的 json 数据。
这是我的 json
"item_tabel" : [
{ // array 0
"method": [
{"item_method": "IT001"},
{"item_method": "IT002"}
],
"innovation": [
{"innovation_item": "Top down wall"},
{"innovation_item" : "Top down Beton"}
],
},
{ // array 1
"method": [
{"item_method": "IT003"},
{"item_method": "IT004"}
],
"innovation": [
{"innovation_item": "Top down wall"},
{"innovation_item" : "Top down Beton"}
],
}
],
这是我的桌子
在每一行和每一列行的表格中,在单选按钮上选择 1 个输入,这是我的代码
<tbody>
<tr v-for="(data, index) in result_estimate.item_tabel" :key="index">
<td>{{index + 1}}</td>
<td v-for="(n, ix) in data.item_name" :key="ix" class="left"> {{n.name}}</td>
<td>
<template v-for="(itm, i) in data.method">
<p :key="i">
<input type="radio" v-model="inp_met[index]" :value="itm.item_value"
@change="handleClickInput(data, index, i, itm.item_value)">
<label>{{itm.item_method}}</label>
</p>
</template>
</td>
<td>
<template v-for="(inn, row_in) in data.innovation">
<p :key="row_in">
<input type="radio" v-model="inp_in[index]" :value="inn.innovation_value">
<label>{{inn.innovation_item}}</label>
</p>
</template>
</td>
</tr>
</tbody>
//button submit
<button type="button" @click="submit_output">Save</button>
这是我的功能
export default {
data(){
return {
inp_met: {},
inp_in : {},
}
},
computed: {
...mapState({ result_estimate: (state) => state.res_estimate }),
},
methods:{
submit_output(){
// I want to make a post format like this
var submit = {
item : [
{ //row 1 in table
inp_met: 'IT002', here i choose index 0 from array to 1
inp_in : 'Top down wall-01'
},
{ //row 2 in table
inp_met: 'IT004', here i choose index 1 from array to 1
inp_in : 'Top down wall-03'
}]
}
console.log(submit);
},
handleClickInput(data, index, i, value) {
console.log(value)
},
}
}
我在提交功能上创建了一个静态格式,如何制作这样的?提前感谢那些帮助过的人。谢谢
解决方案
推荐阅读
- javascript - 我需要在调整窗口大小以及页面加载时重新运行此脚本
- ios - IOS/Objective-C:HTTP Post 到服务器的字符串长度语法
- ionic-framework - 离子应用程序退出时显示提示
- php - PHP 后期静态绑定使用
- java - 如何在android studio中的滚动视图下进行相对布局
- excel - Excel VBA:删除所有不重复的行
- ios - UIKeyboardWillShow 通知在物理设备上调用了两次,但在模拟器中没有
- javascript - 这段代码中的反斜杠在做什么?他们在逃避什么?
- wordpress - Github Pages CSS 在 Wordpress 网站上不起作用
- google-app-engine - 通过 iOS 应用访问 Google ML 引擎