Luc*_*sNa 4 javascript vue.js vue-component vuejs2 vuetify.js
我有一个对象数组:productos[],我用它来填充v-datatable.
我一直在尝试添加搜索texfield,如Vuetify文档所述。我已经添加了这个,但它只适用于(出于某种原因)带有数字的标题,并且它不起作用,例如当你输入一个字符串时。
我想我做错了什么。
搜索文本字段:
<v-text-field
v-model="search"
append-icon="search"
label="Search"
single-line
hide-details
></v-text-field>
Run Code Online (Sandbox Code Playgroud)
v-数据表
<v-data-table
:headers="headers"
:items="productos"
:search="search"
hide-actions
class="elevation-1"
>
<template slot="items" slot-scope="props">
<td class="text-xs-left">{{ props.item.ListadoProductoId }}</td>
<td class="text-xs-left">{{ props.item.ListadoProducto.nombre }}</td>
<td class="text-xs-left"> ${{ props.item.ListadoProducto.precio }}</td>
<td class="text-xs-left">{{ props.item.disponible }}</td>
<td class="text-xs-left">{{ props.item.ListadoProducto.lim_falt }}</td>
<td class="text-xs-left">{{ props.item.ListadoProducto.lim_exc }}</td>
</v-data-table>
Run Code Online (Sandbox Code Playgroud)
标题和其他一些脚本:
export default {
data () {
return {
error: null,
search: '',
headers: [
{text: 'ID_PROD', value: 'ListadoProductoId', sortable: false},
{text: 'Nombre', value: 'nombre'},
{text: 'Precio', value: 'precio'},
{text: 'Disponible (u)', value: 'disponible'},
{text: 'Limite faltantes', value: 'lim_falt'},
{text: 'Limite excedentes', value: 'lim_exc'}
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
Productos 数组示例:
productos: [
{
ListadoProducto: {
id: 5,
lim_exc: 5000,
lim_falt: 200,
nombre: "Algo",
precio: 300
},
ListadoProductoId: 5,
disponible: 100,
id: 5
},
{
ListadoProducto: {
id: 6,
lim_exc: 1000,
lim_falt: 200,
nombre: "Bgo",
precio: 450
},
ListadoProductoId: 6,
disponible: 0,
id: 6
}
]
Run Code Online (Sandbox Code Playgroud)
图片:
无需搜索
用数字搜索(它与第一个标题匹配)
v-data-table如果您的对象值是嵌套的,您必须告诉标题。
假设您的对象结构是:
{
ListadoProducto: {
id: 5,
lim_exc: 5000,
lim_falt: 200,
nombre: "Algo",
precio: 300
},
ListadoProductoId: 5,
disponible: 100,
id: 5
}
Run Code Online (Sandbox Code Playgroud)
在您的标题中指定嵌套节点,例如value: 'ListadoProducto.nombre',这样搜索就知道您的对象不是平面的。
headers: [
{text: 'ID_PROD', value: 'ListadoProductoId', sortable: false},
{text: 'Nombre', value: 'ListadoProducto.nombre'},
{text: 'Precio', value: 'ListadoProducto.precio'},
{text: 'Disponible (u)', value: 'disponible'},
{text: 'Limite faltantes', value: 'ListadoProducto.lim_falt'},
{text: 'Limite excedentes', value: 'ListadoProducto.lim_exc'}
]
Run Code Online (Sandbox Code Playgroud)