在iview的Table中添加Select(render)
首先对Render进行分析,在iview官方的文档中,找到了table插入Button的例子:
- {
- title: 'Action',
- key: 'action',
- width: 150,
- align: 'center',
- render: (h, params) => {
- return h('div', [
- h('Button', {
- props: {
- type: 'primary',
- size: 'small'
- },
- style: {
- marginRight: '5px'
- },
- on: {
- click: () => {
- this.show(params.index)
- }
- }
- }, 'View'),
- h('Button', {
- props: {
- type: 'error',
- size: 'small'
- },
- on: {
- click: () => {
- this.remove(params.index)
- }
- }
- }, 'Delete')
- ]);
- }
这是Table的表头定义中的一段,意思是创建两个按钮,一个名为View,一个名为Delete,在疑惑h是什么的时候,看到网上一哥们的回答顿时茅厕顿开,问题地址,render参数中h可以看做是 createElement。可以看出上面的例子大概表现为一个div中包含两个Button,又根据生成Button的结构可以把这段代码简化一下,写为:
- render: (h, params) => {
- return h('Button', {
- props: {
- type: 'primary',
- size: 'small'
- },
- style: {
- marginRight: '5px'
- },
- on: {
- click: () => {
- this.show(params.index)
- }
- }
- }, 'View'),
- );
- }
在学vue的时候,有看到父组件和子组件之间的交互使用了props,我们在iview的文档中,看到Button的API包括type、size,由此可知,props可以直接声明子组件的API值内容,on中写的自然就是它的触发事件了。
好,现在开始写Table组件中的Select组件:
- render: (h, params) => {
- return h('Select', {
- props:{
- value: this.data[params.index].volumeType,
- },
- on: {
- 'on-change':(event) => {
- this.data[params.index].volumeType = event;
- }
- },
- },
- [
- h('Option',{
- props: {
- value: '1'
- }
- },'option1'),
- h('Option',{
- props: {
- value: '2'
- }
- },'option2')
- ]
- );
- },
可以看到效果:
好,现在我们实现了基本的渲染。现在我们实现动态改变option的内容,与组件的data结合起来,毕竟当数据量大的时候,总不能一个一个的写上去。
观察render的第三个参数为一个对象数组,我们可不可以使用便利数据数组的方式生成呢?(废话)
直接上代码,在数组的地方写入:
- this.volumeTypes.map(function(type){
- return h('Option', {
- props: {value: type}
- }, type);
- })
其中,this.volumeTypes就是我们的列数据,当然,这是最基本的绑定的写法,如果想使用对象数组,自行研究,很easy的~
这是我们的最终结果:
- {
- title: '卷类型',
- key: 'volumeType',
- align: 'center',
- render: (h, params) => {
- return h('Select', {
- props:{
- value: this.data[params.index].volumeType,
- },
- on: {
- 'on-change':(value) => {
- this.data[params.index].volumeType = value;
- }
- },
- },
- this.volumeTypes.map(function(type){
- return h('Option', {
- props: {value: type}
- }, type);
- })
- );
- },
- },
end。
在iview的Table中添加Select(render)的更多相关文章
- iview+vue 表格中添加图片
开门见山,话不多说,要在表格中添加图片,可以使用td: <table " width="100%"> <tr class="tr-style ...
- iview之——table中嵌套input、select等
使用iview在table中嵌入button是比较常见的需求,但是在table中嵌入input或者select你是否考虑过呢?本文用实例介绍input和select在table中的嵌套. 理解tabl ...
- IVIEW组件Table中加入EChart柱状图
展示图如下: 主要利用了render函数和updated()钩子函数进行数据填充与渲染. 1.在Table的Colums中加入 1 { 2 title: '比例图', 3 align: 'center ...
- iview的table中Tooltip的使用
这篇文章主要介绍了iview-admin中在table中使用Tooltip提示效果. 1. table中文字溢出隐藏,提示气泡展示所有信息 jLongText(item){ item.render = ...
- OAF TABLE中添加序号列
在实际的OAF页面TABLE的使用中,会有很多时候需要在前台页面中显示序号,虽然在sql中可以使用rownum来获得序号,但是rounum的优先级比order by 高,所以在语句中order by ...
- jQuery如何追加tr到table中 添加到头或者尾
jQuery 添加新内容有以下四个方法: append() - 在被选元素的结尾插入内容 prepend() - 在被选元素的开头插入内容 after() - 在被选元素之后插入内容 before() ...
- Vue ElementUI表格table中使用select下拉框组件时获取改变之前的值
目前项目中有一个场景,就是表格中显示下拉框,并且下拉框的值可以更改,更改后提交后台更新.因为这个操作比较重要,所以切换时会有一个提示框,提示用户是否修改,是则走提交逻辑,否则直接返回,什么也不做. 之 ...
- table中添加下拉框
{ file: 'usename', title: '下发用户', width:"20%", align: 'center', templet: function (d) { va ...
- iview使用之怎样通过render函数在tabs组件中添加标签
在实际项目开发中我们通常会遇到一些比较'新颖'的需求,而这时iview库里往往没有现成可用的组件示例,所以我们就需要自己动手翻阅IviewAPI进行自定义一些组件,也可以说是将iview库里的多种组件 ...
随机推荐
- 小程序之Tab切换
小程序越来越火了,作为一名,额 有理想的攻城狮,当然要紧跟互联网时代的步伐啦,于是我赶紧抽时间学习了一下小程序的开发,顺便把经验分享给大家. 对于申请账号以及安装开发工具等,大家可以看官网:http ...
- 2018.3.29 div格式设置
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> ...
- 201621123062《java程序设计》第12周作业总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多流与文件相关内容. 思维导图: 2. 面向系统综合设计-图书馆管理系统或购物车 使用流与文件改造你的图书馆管理系统或购物车. 2. ...
- 从0开始的LeetCode生活—001-Two Sum
题目: Given an array of integers, return indices of the two numbers such that they add up to a specifi ...
- C语言——总结回顾
1.当初你是如何做出选择计算机专业的决定的?经过一个学期,你的看法改变了么,为什么? 你觉得计算机是你喜欢的领域吗,它是你擅长的领域吗? 为什么? 答:①当初选择计算机专业是出于一种选择,是一种带着冲 ...
- iOS开发UIKit框架-可视化编程-XIB
1. Interface Builder 可视化编程 1> 概述 GUI : 图形用户界面(Graphical User Interface, 简称GUI, 又称图形化界面) 是指采用图形方式显 ...
- tomca配置文件自动还原问题的解决 server.xml content.xml 等
当我们在处理中文乱码或是配置数据源时,我们要修改Tomcat下的server.xml和content.xml文件. 但是当我们修改完后重启Tomcat服务器时发现xml文件又被还原了,修改无效果. 为 ...
- bootstrap 之下拉多选
效果如图: 一.HTML代码 <label class="col-sm-1 control-label text-right" for="ds_host" ...
- Django 相关
Web框架本质 其实所有的Web应用本质就是一个socket服务端,而用户的浏览器就是一个socket客户端.简单的socket代码如下: import socket sk = socket.sock ...
- mysql中独立表空间与共享表空间之前如何切换
环境 mysql版本:5.7.19 官方文档:(https://dev.mysql.com/doc/refman/5.7/en/innodb-multiple-tablespaces.html) 查看 ...