Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 单击具有模板行的v-data-table中的行_Javascript_Vue.js_Vuejs2_Vue Component_Vuetify.js - Fatal编程技术网

Javascript 单击具有模板行的v-data-table中的行

Javascript 单击具有模板行的v-data-table中的行,javascript,vue.js,vuejs2,vue-component,vuetify.js,Javascript,Vue.js,Vuejs2,Vue Component,Vuetify.js,当我添加模板行时(以便它们具有基于条件的特殊格式): clickedHandle应在行单击上记录一些值。尝试使用以下代码: <v-data-table :headers="headers" :items="desserts" hide-actions class="elevation-1" > <template slot="items&quo

当我添加模板行时(以便它们具有基于条件的特殊格式):

clickedHandle
应在行单击上记录一些值。

尝试使用以下代码:

<v-data-table
      :headers="headers"
      :items="desserts"
      hide-actions
      class="elevation-1"
    >
     <template slot="items" slot-scope="myprops">
  <tr v-if="myprops.item.name.includes('Fro')">
 ...
  </tr>
  <tr v-else>
    <td v-for="itemx in props.item">{{ itemx }}</td>
  </tr>
</template>
    </v-data-table>

...
{{itemx}}

像在
v-data-table
行自定义一样,单独自定义每个单元格,而不是整行。您可以使用
v-for
动态定位所需的单元格插槽(与
myheaders
数组结合使用):


{{toThousands(props.item[header])}
{{props.item[header]}
您可以通过在计算时间内提前准备数据来避免这种时隙和过滤器复杂性


这是一个更新的

,但我需要表格条件格式的模板部分我刚刚更新了我的答案我不确定你是否理解这个问题,因为你的答案中根本没有点击机制。如果我有动态列名(第一列除外),该怎么办?这就是为什么我使用这个列表
myheaders
,以便从中选择列名。这就是为什么不能手动选择
props.item.carries
谢谢,我不确定过滤器是否是最好的用例,因为这个
scaleSelect
变量在我的应用程序中被更改,在过滤器功能之外,然后基于我设置数据格式的值。但是有了这个过滤器,这个表似乎就坏了:你可以使用这个方法。请记住,在计算机中准备数据是非常理想的,它更像是对表中的值应用方法,而不是为表提供预先格式化的值,这似乎更简单,但结果更复杂。如果应用程序较大,模板方法可能会导致应用程序变慢,因为
includes
函数必须在每次重新渲染时搜索每个项目
clickedHandle(value) {
  console.log(value);
},
<v-data-table
      :headers="headers"
      :items="desserts"
      hide-actions
      class="elevation-1"
    >
     <template slot="items" slot-scope="myprops">
  <tr v-if="myprops.item.name.includes('Fro')">
 ...
  </tr>
  <tr v-else>
    <td v-for="itemx in props.item">{{ itemx }}</td>
  </tr>
</template>
    </v-data-table>