鍍金池/ 問答/HTML/ 設(shè)置數(shù)值遇到的問題

設(shè)置數(shù)值遇到的問題

{
    title: 'Age',
    key: 'age',
    render: (h, params) => {
      return h(
        'Input',
        {
          props: {
            value: params.row.age,
          },
          on: {
            'on-change': (event) => {
              this.data1[params.index].age = event.target.value;
              this.data1.forEach(item => {
                if(item.type === this.data1[params.index].type) {
                  item.age = this.data1[params.index].age;
                }
              })
            }
          }
        },
        name
      );
    }
  }

data: 
data1: [
          {
            type: 1,
            name: 'John',
            age: 24
          },
          {
            type: 1,
            name: 'Jim',
            age: 24
          },
          {
            type: 2,
            name: 'Joe',
            age: 30
          }
        ],

在iview 的table 中插入了input組件,現(xiàn)在想在編輯其中一行的時候,data1中,type相同的數(shù)據(jù)能一起改變,單按照上面的forEach寫法,每次在input中輸入一個值后,就會自動失去焦點,光標(biāo)自動跳出input框,請問一下大神們,有沒有方法可以解決? 萬分感謝??!

回答
編輯回答
硬扛

因為輸入之后 render 重新渲染了 table,所以會失去焦點吧。這個感覺無法避免唉,不過你可以優(yōu)化。你可以寫個防抖函數(shù)讓延時多少毫秒觸發(fā)。
擼了個例子,可以試試。
鏈接描述

2017年9月9日 08:32