我正在尝试过滤正在动态重新索引的数组。
我想要一个匹配多个属性的字符串的输入字段。
<paper-input value="{{val}}" placeholder="Filter Cards"></paper-input>
<template is="dom-repeat" items="[[restructure(data)]]" initial-count="2" filter="{{filter(val, data)}}">
<card-items data="[[item]]" items="[[item.items]]" links="false"></card-items>
</template>
...
此函数重组要为卡片布局格式化的数据。
returnInvoices(data) {
let newData = [];
for (let i = 0; i < data.length; i++) {
let noOrder = data[i].noOrder;
if (!newData[noOrder]) {
newData[noOrder] = {
idMaster: data[i].idMaster,
itemId: data[i].itemId,
description: data[i].description,
noOrder: noOrder,
items: []
};
}
newData[noOrder].items.push('{' +
'"idMaster":"' + data[i].idMaster + '",' +
'"itemId":"' + data[i].itemId + '"}');
}
return newData.filter(val => val).sort((a, b) => {return b.noInvoice - a.noInvoice}) // reindex array
}
我希望此函数返回数组中具有与字符串匹配的属性的对象。
filter(val, data) {
if (!val) return null;
else {
val = val.toLowerCase();
// not sure what to do here
// would like to filter on all object properties (from data)
return data[0];
}
}
...
例子
if(val == 1) return data[0] & data[1];
if(val == 'Item') return data[0] & data[2];
对于数据数组
let data = [
{"itemId": "1", "description": "Nice Item", "noOrder": 123},
{"itemId": "2", "description": "Good Product", "noOrder": 123},
{"itemId": "3", "description": "Fine Item", "noOrder": 444}
}
...
如何过滤所有 3 个属性的字符串?
如何使用过滤器作为重组的中间功能?