使用iview在table中嵌入button是比较常见的需求,但是在table中嵌入input或者select你是否考虑过呢?本文用实例介绍input和select在table中的嵌套。

理解table如何嵌套input、select首先要理解vue的render函数可以参考:vue render函数介绍。当然,不理解直接Ctrl + C也是可以使用的 ^_^

在iview的官方文档中,table插入Button的例子如下:

 1             {
2 title: 'Action',
3 key: 'action',
4 width: 150,
5 align: 'center',
6 render: (h, params) => {
7 return h('div', [
8 h('Button', {
9 props: {
10 type: 'primary',
11 size: 'small'
12 },
13 style: {
14 marginRight: '5px'
15 },
16 on: {
17 click: () => {
18 this.show(params.index)
19 }
20 }
21 }, 'View')
22 ]);
23 }

由文档得知,table组件提供一个api:render函数,可以自定义渲染当前列,包括渲染自定义组件,它基于 Vue 的 Render 函数。

参数解读:

h:  vue  Render函数的别名(全名 createElement)即 Render函数

params: table 该行内容的对象

props:设置创建的标签对象的属性

style:设置创建的标签对象的样式

on:为创建的标签绑定事件

所以代码中的render函数,即创建的一个div中包裹一个button按钮,同时给button设置了相关属性和绑定事件

那么如下图又该如何实现呢:

代码如下:

 <template>
<div class="meeting">
<Table border :columns="columns" :data="data" :height="tableHeight"></Table>
</div>
</template>
 <script>
export default {
name: "meeting",
data() {
          let t = this
return {
tableHeight:'550',
columns: [
{
title: '责任人',
key: 'associated',
width: 100,
align: 'center',
},
{
title: '预计工时',
key: 'attendee',
width: 100,
align: 'center',
render:(h,params) => {
return h('Input',{
props: {
value:'',
size:'small',
},
on: {
input: (val) => {
t.data[params.index].estimateTime = val
}
},
})
}
},
{
title: '实际工时',
key: 'state',
width: 100,
align: 'center',
render:(h,params) => {
return h('Input',{
props: {
value:'',
size:'small',
},
on: {
input: (val) => {
t.data[params.index].actualTime = val
}
}, })
}
},
{
title: 'WorkHover状态',
key: 'action',
width: 150,
align: 'center',
render: (h, params) => {
return h('Select',{
props:{
},
on: {
'on-change':(event) => {
this.data[params.index].volumeType = event;
}
},
},
params.row.action.map((item) =>{
return h('Option', {
props: {
value: item.value,
label: item.name
}
})
})
)
}
}, ],
data: [
{
associated: '123',
action:[
{
value:0,
name:'select A'
},
{
value:1,
name:'select B'
},
]
},
{
associated: '123',
action:[
{
value:0,
name:'select A'
},
{
value:1,
name:'select B'
},
]
},
],
}
},
methods: {}
};
</script>

讲解:

这里是在table组件中嵌入了iview的input和select组件

值得注意的是,1、on是table的触发事件,不是table内嵌套组件的触发事件,2、对于select组件,通过map函数就可以代替v-for的渲染(注:如果数据中的value值为空,select将不被渲染)

iview之——table中嵌套input、select等的更多相关文章

  1. jQuery 在Table中选择input之类的东西注意事项

    jQuery 在Table中选择input之类的东西注意事项: 如果不在td标签中,是不能进行正确选择的: <table id="tblFormId"> <tr& ...

  2. iview的table中Tooltip的使用

    这篇文章主要介绍了iview-admin中在table中使用Tooltip提示效果. 1. table中文字溢出隐藏,提示气泡展示所有信息 jLongText(item){ item.render = ...

  3. 在iview的Table中添加Select(render)

    首先对Render进行分析,在iview官方的文档中,找到了table插入Button的例子: { title: 'Action', key: 'action', width: 150, align: ...

  4. table中嵌套table,如何用jquery来控制奇偶行颜色

    总是要趁着自己还有记忆的时候,把该记录下来的都记录下来,着实是不敢恭维自己的记性. 相信很多时候,我们前端人员,经常会用到table里面的某个td中还嵌套着table,而这个时候还总要去弄奇偶行的颜色 ...

  5. angular中的 input select 值绑定无效,以及多出一个空白选项问题

    问题: <!-- 问题标签 --> <select ng-model="sortType"> <option value="1"& ...

  6. IVIEW组件Table中加入EChart柱状图

    展示图如下: 主要利用了render函数和updated()钩子函数进行数据填充与渲染. 1.在Table的Colums中加入 1 { 2 title: '比例图', 3 align: 'center ...

  7. iview框架modal中嵌套modal

    modal的使用是平级的,后面的会覆盖前面,如下<modal>111</modal><modal>222</modal>内容为222的弹框会在内容为11 ...

  8. iview中table里嵌套i-switch、input、select等

    iview中table内嵌套 input render:(h,params) => { return h('Input',{ props: { value:'', size:'small', } ...

  9. js循环获取table中的值

    <script type="text/javascript"> function getTdValue() { var tableId = document.getEl ...

随机推荐

  1. PHP多图片上传 并检查 加水印 源码

    参数说明:$max_file_size : 上传文件大小限制, 单位BYTE$destination_folder : 上传文件路径$watermark : 是否附加水印(1为加水印,其他为不加水印) ...

  2. 安卓手机作为中继器-连接Wifi共享该Wifi给PC和手机

    工具 routernet.apk

  3. [Python3 练习] 003 货币转换

    题目:货币转换 (1) 描述 人民币和美元是世界上通用的两种货币,写一个程序进行货币间币值转换 记人民币和美元之间的汇率为:1 美元 = 6.78 人民币 程序可以接受人民币或美元输入,转换为另一种货 ...

  4. mysql 多表查询 以及 concat 、concat_ws和 group_concat

    left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录right join(右联接) 返回包括右表中的所有记录和左表中联结字段相等的记录inner join(等值连接) 只返 ...

  5. JAVA总结--Spring框架全解

    一.Spring简介 Spring 是个java企业级应用的开源开发框架.Spring主要用来开发Java应用,但是有些扩展是针对构建J2EE平台的web应用.Spring 框架目标是简化Java企业 ...

  6. JDK11 | 第二篇 : JShell 工具

    文章首发于公众号<程序员果果> 地址 : https://mp.weixin.qq.com/s/saHBSTo4OjsIIqv_ixigjg 一.简介 Java Shell工具是JDK1. ...

  7. 面试题思考:Stack和Heap的区别 栈和堆的区别

    堆栈的概念: 堆栈是两种数据结构.堆栈都是一种数据项按序排列的数据结构,只能在一端(称为栈顶(top))对数据项进行插入和删除.在单片机应用中,堆栈是个特殊的存储区,主要功能是暂时存放数据和地址,通常 ...

  8. SCAU 2015 GDCPC team_training1

    A: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1525 题意:前两段都是废话 , 然后给出一个 p( p(a) ) = p(a) 的公式给你 ...

  9. Gradle Could not find method leftShift() for arguments

    task hello << { println 'Hello world!' } 其中 << 在gradle 在5.1 之后废弃了 可以查看gradle 版本号 gradle ...

  10. TP框架中的M、D、C、I、A、S方法

    M方法 M实例化参数是数据库的表名 //使用M方法实例化$User = M('User');//和用法$User = new /Think/Model ('User');等效//执行其他的数据操作$U ...