iview之——table中嵌套input、select等
使用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等的更多相关文章
- jQuery 在Table中选择input之类的东西注意事项
jQuery 在Table中选择input之类的东西注意事项: 如果不在td标签中,是不能进行正确选择的: <table id="tblFormId"> <tr& ...
- iview的table中Tooltip的使用
这篇文章主要介绍了iview-admin中在table中使用Tooltip提示效果. 1. table中文字溢出隐藏,提示气泡展示所有信息 jLongText(item){ item.render = ...
- 在iview的Table中添加Select(render)
首先对Render进行分析,在iview官方的文档中,找到了table插入Button的例子: { title: 'Action', key: 'action', width: 150, align: ...
- table中嵌套table,如何用jquery来控制奇偶行颜色
总是要趁着自己还有记忆的时候,把该记录下来的都记录下来,着实是不敢恭维自己的记性. 相信很多时候,我们前端人员,经常会用到table里面的某个td中还嵌套着table,而这个时候还总要去弄奇偶行的颜色 ...
- angular中的 input select 值绑定无效,以及多出一个空白选项问题
问题: <!-- 问题标签 --> <select ng-model="sortType"> <option value="1"& ...
- IVIEW组件Table中加入EChart柱状图
展示图如下: 主要利用了render函数和updated()钩子函数进行数据填充与渲染. 1.在Table的Colums中加入 1 { 2 title: '比例图', 3 align: 'center ...
- iview框架modal中嵌套modal
modal的使用是平级的,后面的会覆盖前面,如下<modal>111</modal><modal>222</modal>内容为222的弹框会在内容为11 ...
- iview中table里嵌套i-switch、input、select等
iview中table内嵌套 input render:(h,params) => { return h('Input',{ props: { value:'', size:'small', } ...
- js循环获取table中的值
<script type="text/javascript"> function getTdValue() { var tableId = document.getEl ...
随机推荐
- 用Vue来实现音乐播放器(十四):歌手数据接口抓取
第一步:在api文件夹下创建一个singer.js文件 返回一个getSingerList()方法 使他能够在singer.vue中调用 import jsonp from '../common/j ...
- 只有一个form 的程序, onactivate 只触发一次。
https://blog.csdn.net/saint13/article/details/454615 Form的onActivate事件 2005年08月15日 01:08:00 阅读数:3406 ...
- R语言中的几种数据结构
R语言中的几种数据结构 一 R中对象的5种基本类型 字符(character) 整数 (integer) 复数(complex) 逻辑(logical:True/False) 数值(numeric: ...
- [转载]OpenSSL中文手册之命令行详解(未完待续)
声明:OpenSSL之命令行详解是根据卢队长发布在https://blog.csdn.net/as3luyuan123/article/details/16105475的系列文章整理修改而成,我自己 ...
- Git - 版本回溯
在git push的时候,有时候我们会想办法撤销git commit的内容 1.找到之前提交的git commit的id git log 找到想要撤销的id 2.git reset –hard id ...
- python实现建立tcp通信
实现代码如下: #tcp协议通信import socketclass TcpConnect: def get_tcp(self,ip,port,message): #实例化一个基于tcp的socket ...
- 远程访问其他主机的Mysql(Ubuntu)
远程访问其他主机的Mysql 首先:被访问的电脑应该把防火墙关掉, sudo ufw disable 然后去etc/mysql sudo gedit my.cnf 将bind-address注解掉 由 ...
- vue观察模式浅析
以下是我对vue观察者模式的理解:github L6zt 加入tip 2018-10-14 最近又看到<js设计模式设计>书 推荐去搂搂不要对框架的偏见, 你真的了解jquery.angu ...
- Django 的 logging日志文件配置
在Django的settings配置文件里配置以下信息: import os BASE_LOG_DIR = os.path.join(BASE_DIR , "log") # log ...
- Spring Boot 全局排除 spring-boot-starter-logging 依赖
https://blog.csdn.net/u013314786/article/details/90412733 项目里使用了log4j2做日志处理,要排除掉Spring Boot 很多jar里边默 ...