一、前言
1、mark
本來一開始是想的,在change事件里面,有個參數叫text的,結果沒有。
底層應該不支持,其它方式應該可以,到時候看看黎大神給的方案。
目前可行的感覺就這種
change: ({value,column}) => {
//console.log(this.$refs.crud.DIC.productAttributeCategoryId);
},
2、源碼預覽
二、解決方案1
1、原理
在change事件中,獲取到value,然后在dic中,用過查詢換取text(走了彎路)
2、代碼
2.1 品牌name
{
label: "品牌名稱",
prop: "brandName",
rules: [{
required: false,
message: "請輸入品牌名稱",
trigger: "blur"
}],
hide: true,
display:false,
},
2.2 品牌id
{
label: "品牌",
prop: "brandId",
rules: [{
required: false,
message: "請輸入品牌",
trigger: "blur"
}],
hide: true,// 在列上隱藏
type: "select",
dicUrl: "/api/blade-pms/brand/select",
props: {
label: "name",
value: "id"
},
change: ({value, column}) => {
const text = this.getDicSelectText(column.prop, value);
this.form.brandName = text;
},
},
2.3 在字典中,通過字典類型和id換取name
getDicSelectText(type, value) {
if (validatenull(value)) {
return "";
}
const bl = this.$refs.crud.DIC.hasOwnProperty(type);
if (bl) {
const obj = this.$refs.crud.DIC[type].find(item => item.id == value);
if (!validatenull(obj)) {
return obj.name;
}
}
return "";
},
三、解決方案2
1、偶然發現的,游覽器傳輸數據的時候,帶了$brandId,這個就是品牌name
2、源碼應該是在這里賦的值
3、具體使用,直接在保存前賦值就可以了
row.brandName=row.$brandId;
row.productAttributeCategoryName=row.$productAttributeCategoryId;