vue.js-如何更新JSON
vue.js - how to update JSON?
我失去了vue.js的基础:/我想在点击按钮后在html中添加新列,但我无法访问json中的特定位置。
<div id="app">
<div class="container">
<div class="row" v-for="row in json._children">
<div class="col-xs-{{ col.size }}" v-for="col in row._children">
<div v-for="module in col._children">
{{module.moduleType}}
</div>
<button v-on:click="addModule(col, $event)">Add</button>
</div>
</div>
</div>
</div>
JS-
new Vue({
el: '#app',
data: {
json: {
'type': 'panel',
'_children': [
{ 'type': 'row', '_children': [ { 'type': 'col', 'size': '2' }, { 'type': 'col', 'size': '10', '_children': [{ 'type': 'module', 'moduleType': 'HTML' }] } ] },
{ 'type': 'row', '_children': [ { 'type': 'col', 'size': '5' }, { 'type': 'col', 'size': '7' } ] }
]
}
},
methods: {
addModule: function(currentColumn, e) {
// ????????
}
}
});
有人能帮忙吗?提前感谢
如果要向行添加列,则应将该行传递给addModule()
。不是吗?此外,我通过$index
来知道在哪个位置插入新列:
<button v-on:click="addModule(row, $index, $event)">Add</button>
那么您所要做的就是将新对象CCD_ 3放入行的CCD_。
methods: {
addModule: function(row, colIndex, e) {
var newCol = { type: 'col', size: 1 }
row._children.splice(colIndex, 0, newCol)
//or to insert to the right:
row._children.splice(colIndex + 1, 0, newCol)
}
}
相关文章:
- Ajax POST返回成功,但没有;t更新JSON文件
- 如何使用 PHP 更新 JSON 文件中的值
- 比较 2 个 JSON 并在更新 json 时更改键值
- 在javascript中更新JSON.parsed对象
- React在重新渲染时未更新JSON提要
- vue.js-如何更新JSON
- 使用AngularJS根据输入值更新json文件
- mongodb更新JSON数组
- 使用循环更新 JSON 属性值
- 使用动态变量名更新JSON中的结果
- AngularJS:使用特定键以模式更新JSON
- 用JavaScript更新JSON数据
- 使用angular更新json值
- 使用 angular.js 获取和更新 json
- 复制对象,然后更新 JSON 对象中的值
- 使用 AJAX Jquery 更新 JSON
- 更新 JSON 键值 - AngularJS
- 如果尝试使用相同的键名称,请更新 json 值
- 如何做一个HTML选择表单,其中所选选项更新JSON值
- 在不刷新页面的情况下更新 json 数据