【问题标题】:Element UI, passing id to table column with checkbox元素 UI,使用复选框将 id 传递给表列
【发布时间】:2020-05-29 13:06:32
【问题描述】:

有没有办法使用selection 类型将id 传递给el-table-column?我试过传递一个插槽,但是复选框没有呈现。这是代码:

<el-table-column>
    <template slot-scope="scope" v-if="scope.row">
      <div :id="`column-${scope.row.name}`">{{ `reports-${scope.row.name}` }}</div>
    </template>
  </el-table-column>
  <el-table-column prop="selected" align="center" type="selection" class-name="checkbox-column">
</el-table-column>

第一列通过作用域槽获取 id。

【问题讨论】:

  • 在 Skype 上联系我,让我们弄清楚。 Skype ID:syed_haroon
  • @Syed 非常感谢您抽出宝贵时间!格式化程序对我不起作用,我最终从作用域插槽中捕获了行名:) 所以在我的第一列中,我没有直接返回一个字符串,而是将它传递给一个函数:&lt;div&gt;{{ getRowName(scope.row.name) }}&lt;/div&gt; 并在这个函数中存储这个名称到变量并作为类名传递到第二列
  • UPD:我的解决方案没有成功

标签: vue.js element-ui


【解决方案1】:

如果您对class 没问题,请使用cell-class-name 而不是ID

在你的template

<el-table your-attrs ...  :cell-class-name="cellClassName">

在你的script

methods: {
  cellClassName({row, column, rowIndex, columnIndex}) {
    if (columnIndex === 1) return `checkbox-${rowIndex}`;
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-29
    • 1970-01-01
    相关资源
    最近更新 更多