iView 通过render函数 实现 InputNumber 的双向数据绑定,踩坑一、

InputNumber 踩坑“

先给效果图:

 html:

<!-- 列表 -->
                <Col span="15">
                    <Table border size="small" ref="selection" :height="height" :columns="historyColumns" :data="historyData" @on-select-all="selectTable" @on-select-all-cancel="selectTable_Cancel" @on-select-cancel="item_Cancel" @on-select="row_Select" @on-selection-change="row_Select">
                    </Table>
                    <Row type="flex" style="margin-top:10px">
                        <Col span="2" style="margin-left: 1.5%;" v-show="selectData == true">
                            <span style="display:inline-block; height:32px; line-height:32px;">音量值:</span>
                        </Col>
                        <Col span="3" v-show="selectData == true">
                            <InputNumber type="number" v-model="volume" :min="0" :max="40"></InputNumber>
                        </Col>
                        <Col span="3">
                            <div style="position: fixed;right: 5%;" v-show="showSumit">
                                <Button size="large" style="padding: 10px 15px 10px 15px;" type="primary" @click="sumitData()">提交</Button>
                            </div>
                        </Col>
                    </Row>
                </Col>

js:

 return { 
    volume: null,
    historyColumns: [   
                    {type: 'selection',width:60,align: 'left'},
                    {title: '序号', type:'index', align:'center', width:70},
                    {title: '线路', key: 'lineName',width:80},
                    {title: '车站', key: 'stationName'}, 
                    {title: '分区', key: 'areaName'},
                    {title: '音量', key: 'volume',width:90,align:'center',type:'number',
                        render:(h,params)=>{
                            return h('div',[
                                h('InputNumber',{
                                    props:{
                                        min: 0,
                                        max: 40,
                                        value: this.volume !== null ? this.volume : params.row.volume,
                                    },
                                    style:{
                                        height: "30px !important",
                                        width: "95%",
                                    },
                                    on:{
                                        'on-change':(event)=>{
                                            // console.log("InputNumber:",event);
                                            // params.row.volume = event;
                                            this.historyData[params.index].volume = event;
                                        }
                                    }
                                })
                            ])
                        }
                    },
}

尤其注意的是后台返回列表: this.historyData = res.data.result;

但是列表为啥不显示:音量值呢?

这里需要判断下,你这volume的值  是   定义的 this.volume 的值,还是 this.historyData[i].volume 的值。

三元表达式就可以解决了。

 value: this.volume !== null ? this.volume : params.row.volume,

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

IT博客技术分享

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值