原数据
tableData = [
{
A: '12A',
B: '12B'
},
{
A: '13A',
B: '13B'
}
]
D替换key和value中的A之后,顺序变了
HTML渲染
<el-table ref="tableRef" :data="tableData" size="mini" style="width: auto" @cell-mouse-enter="handleCellEnter"
@cell-mouse-leave="handleCellLeave" @cell-click="cellClick" @header-click="headerClick"
:header-cell-style="{ 'text-align': 'center', 'font-size': '16px', 'cursor': 'pointer' }"
:cell-style="{ 'text-align': 'center' }">
<el-table-column v-for="(item, index) in titleData" :key="index" :prop="keysData[index]" :label="keysData[index]">
<div slot-scope="scope">
<div class="seat" v-if="scope.row[keysData[index]] != null">
<div class="yiru">{{ scope.row[keysData[index]] }}</div>
<div class="yichu">
<el-button type="primary">禁用</el-button>
</div>
</div>
<div class="noSeat" v-else>
<div class="yiru">{{ scope.row[keysData[index]] }}</div>
<div class="yichu">
<el-button type="primary">启用</el-button>
</div>
</div>
</div>
</el-table-column>
</el-table>
替换方法
this.tableData.forEach(item => {
for (let k in item) {
if (k == column.property && item[k] != null) {
item[k] = item[k].replace(k, value)
if (item.hasOwnProperty(column.property)) {
item[value] = item[k]
delete item[k]
}
}
}
})
这个是座位图,每一个key是每一列的编号,编号修改了,那一列的座位号中的字母也要跟着变,现在头疼的是改完后数据顺序变了,编码和座位号对不上,所以我希望得到结果是替换完之后,数据顺序保持不变。或者大家有别的好方法好思路可以指导一下
tableData = [
{
D: '12D',
B: '12B'
},
{
D: '13D',
B: '13B'
}
]
Javascript
中对象的键的顺序遵循数字键的升序和非数字键的插入顺序。也就是说,JS
会把看起来像数字的键提前并按升序排序,剩下的按插入顺序排序,如:所以只要键不是数字就可以