lov多选模式下,输入框中的内容如果比较长的话可能会无法完整地显示文字内容,这时候就希望在鼠标悬停时能有popover将完整的文字展示出来。
组件原本没有提供这个功能,但是这难不倒冰雪聪明的我,让我们来开动小脑瓜,使用一些奇奇怪怪的小方法来实现它。
const ds = (setLovTitle = () => {}) => ({
fields: [
{
name: 'fieldName',
label: '我是label',
type: 'object',
multiple: true,
lovCode: 'HELLO.MY_LOV_CODE',
},
],
events: {
update: ({ name }) => {
if (name === 'fieldName') {
setTimeout(() => {
setLovTitle(name);
}, 2000);
}
},
},
});
/**
* @description: 給多选lov内容添加悬浮title,要打开element面板分析一下dom结构,就能写出来了
* @author: ChenJJ
* @param {String} id dom元素id
*/
setMultiLovTitle = (id) => {
const field = document.getElementById(id);
if (field) {
const father = field.parentNode;
if (father) {
const ul = father.parentNode;
if (ul) {
const divList = ul.getElementsByTagName('div');
if (divList) {
for (let i = 0; i < divList.length; i++) {
const content = divList[i].innerText;
divList[i].setAttribute('title', content);
}
}
}
}
}
};
<Form dataSet={this.ds}>
<Lov
name="fieldName"
id="fieldName"
// 只在onChange里面写是不够的,后面再打开modal框去改变内容时,是无法触发这个的,但是可以写在dataSet的events里面的update监听回调函函数里面。
onChange={this.setMultiLovTitle('fieldName')}
/>
</Form>