用vue+element-ui寫了一個table,但是table數(shù)據(jù)要和上面的用戶自定義規(guī)格屬性相關聯(lián),生成類似排列組合的table數(shù)據(jù),規(guī)格屬性可增,刪,改,table數(shù)據(jù)可以操作,經過n久的掙扎,table數(shù)據(jù)終于可以渲染出來了,但是因為后面的固定table屬性和前面的用戶自定義屬性是兩個不同的部分,是拼上去的,我一改規(guī)格屬性,自定義屬性可以排列組合渲染出來,但是后面的數(shù)據(jù)就會錯亂,后面的固定屬性數(shù)據(jù)是從上到下依次排列的,而不是排列組合,求大神指點改怎么解決。怎么讓table數(shù)據(jù)自動響應規(guī)格屬性的變化而生成。萬分感謝
<el-table :data="tableDatas.slice((currentPage-1)*pageSize,currentPage*pageSize)">
<el-table-column v-for="customProp in customProps" :key="customProp.prop" :prop="customProp.prop" :label="customProp.label" align="center"></el-table-column>
<el-table-column v-for="tableProp in tableProps" :key="tableProp.prop" :prop="tableProp.prop" :label="tableProp.label" align="center">
<template slot-scope="scope">
<el-input type="text" v-model="scope.row[tableProp.prop]"></el-input>
</template>
</el-table-column>
<el-table-column prop="sale" label="銷量" align="center"></el-table-column>
<el-table-column label="屬性圖" align="center">
<template slot-scope="scope" >
<el-upload
action="/res-upload/upload?dir=/test/1"
:show-file-list="false"
:on-success="uploadItem">
<img class="tableImg" v-if="scope.row.pic1" :src="scope.row.pic1">
<el-button v-else type="primary" size="small" @click="uploadBtn(scope.$index)">上傳</el-button>
</el-upload>
</template>
</el-table-column>
</el-table>
//添加主屬性
addCustomProp(){
var addData={
prop:"",
label:"",
val:[]
}
this.customProps.push(addData)
},
//實際添加主屬性
createCustomProp(label,index){
for(var i=0;i<this.customProps.length;i++){
if(this.customProps[i].label==label&&i!=index){
this.commonFuns.errorAlert(this,"不能添加重復屬性");
this.customProps.splice(index,1);
break;
}else{
this.customProps[i].prop=this.customProps[i].label;
}
}
},
//添加子屬性
addCustomPropVal(index){
var addData={
prop:this.customProps[index].label,
label:""
}
this.customProps[index].val.push(addData);
},
//實際添加子屬性
createCustomPropVal(label,parentIndex,index){
for(var i=0;i<this.customProps[parentIndex].val.length;i++){
if(this.customProps[parentIndex].val[i].label==label&&i!=index){
this.commonFuns.errorAlert(this,"不能添加重復屬性");
this.customProps[parentIndex].val.splice(index,1);
break;
}
}
this.renderTable();
},
//刪除主屬性
delCustomProp(label,index){
this.customProps.splice(index,1);
this.renderTable();
},
//刪除子屬性
delCustomPropVal(label,parentIndex,index){
this.customProps[parentIndex].val.splice(index,1);
for(var i=this.tableDatas.length-1;i>=0;i--){
for(var key in this.tableDatas[i]){
if(this.tableDatas[i][key]==label){
this.tableDatas.splice(i,1)
break;
}
}
}
},
renderTable(parentIndex,index){
// this.tableDatas = [];
var otdData = [];
// console.log(this.customProps)
this.customProps.forEach(function (item, index) {
otdData.push(item.val);
})
//生成縱向表格數(shù)據(jù)
var td1 = [];
var td2 = [];
var td3 = [];
var oTd = [];
for (let i = 0; i < otdData.length; i++) {
for (let w = 0; w < otdData[0].length; w++) {
if( 1 < otdData.length ) {
for (let q = 0; q < otdData[1].length; q++) {
if( 2 < otdData.length ) {
for (let e = 0; e < otdData[2].length; e++) {
switch(i)
{
case 0:
td1.push(otdData[i][w]);
break;
case 1:
td2.push(otdData[i][q]);
break;
case 2:
td3.push(otdData[i][e]);
break;
default:
break;
}
}
}else{
switch(i)
{
case 0:
td1.push(otdData[i][w]);
break;
case 1:
td2.push(otdData[i][q]);
break;
default:
break;
}
}
}
}else{
td1.push(otdData[i][w]);
}
}
switch(i)
{
case 0:
oTd.push (td1);
break;
case 1:
oTd.push (td2);
break;
case 2:
oTd.push (td3);
break;
default:
break;
}
td1 = [];
td2 = [];
td3 = [];
}
//生成橫向表格數(shù)據(jù),加入默認欄目內容
var oId={};
var oItem={};
var cloneTable=[];
if(oTd.length){
for (let i = 0; i < oTd[0].length; i++) {
for(let k = 0; k < oTd.length; k++){
// if(this.tableDatas[i]){
// oId = {
// // costPrice:"",
// originalprice:this.tableDatas[i].originalprice,
// presentprice:this.tableDatas[i].presentprice,
// inventory:this.tableDatas[i].inventory,
// code:this.tableDatas[i].code,
// barcode:this.tableDatas[i].barcode,
// sale:this.tableDatas[i].sale,
// pic1:this.tableDatas[i].pic1,
// [oTd[k][i].prop] : oTd[k][i].label
// };
// }else{
oId = {
// costPrice:"",
originalprice:0,
presentprice:0,
inventory:0,
code:"",
barcode:"",
sale:0,
pic1:"",
[oTd[k][i].prop] : oTd[k][i].label
};
// }
oId["standard"+(k+1)+"value"]=oTd[k][i].label;
oItem = Object.assign(oItem, oId);
oId = {};
}
cloneTable.push(oItem);
oItem = {};
}
}
this.tableDatas=cloneTable;
// console.log(this.tableDatas)
}北大青鳥APTECH成立于1999年。依托北京大學優(yōu)質雄厚的教育資源和背景,秉承“教育改變生活”的發(fā)展理念,致力于培養(yǎng)中國IT技能型緊缺人才,是大數(shù)據(jù)專業(yè)的國家
達內教育集團成立于2002年,是一家由留學海歸創(chuàng)辦的高端職業(yè)教育培訓機構,是中國一站式人才培養(yǎng)平臺、一站式人才輸送平臺。2014年4月3日在美國成功上市,融資1
北大課工場是北京大學校辦產業(yè)為響應國家深化產教融合/校企合作的政策,積極推進“中國制造2025”,實現(xiàn)中華民族偉大復興的升級產業(yè)鏈。利用北京大學優(yōu)質教育資源及背
博為峰,中國職業(yè)人才培訓領域的先行者
曾工作于聯(lián)想擔任系統(tǒng)開發(fā)工程師,曾在博彥科技股份有限公司擔任項目經理從事移動互聯(lián)網管理及研發(fā)工作,曾創(chuàng)辦藍懿科技有限責任公司從事總經理職務負責iOS教學及管理工作。
浪潮集團項目經理。精通Java與.NET 技術, 熟練的跨平臺面向對象開發(fā)經驗,技術功底深厚。 授課風格 授課風格清新自然、條理清晰、主次分明、重點難點突出、引人入勝。
精通HTML5和CSS3;Javascript及主流js庫,具有快速界面開發(fā)的能力,對瀏覽器兼容性、前端性能優(yōu)化等有深入理解。精通網頁制作和網頁游戲開發(fā)。
具有10 年的Java 企業(yè)應用開發(fā)經驗。曾經歷任德國Software AG 技術顧問,美國Dachieve 系統(tǒng)架構師,美國AngelEngineers Inc. 系統(tǒng)架構師。