iView table动态设置filters

官方栗子请点这里

常规写法都是把filters写死了的

columns: [
    ..., {
        ...,
        filters: [{
            label: 'Greater than 25',
            value: 1
        }, {
            label: 'Less than 25',
            value: 2
        }],...
    },...
]
  
  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

但是有时候我们需要的是可以根据后台所给的数据初始化filters,这时候需要做的并不是filters: this.variable,而是:

function(variable) {
    this.columns[index].filters = variable;
}
  
  
  • 1
  • 2
  • 3

iView table组件会监听columns和data的改变而重新渲染。

但是如果是写成上述filters: this.variable方式

  • 首先vue加载的时候运行到this.variable,此时this.variable的值为undefined
  • 然后table组件并不会监听到columns的变化而重新渲染,至于监听不到的原因可以去查看源码(我是不会说我找不到证据的)

猜你喜欢

转载自blog.csdn.net/bc_aptx4869/article/details/80647096
今日推荐