【发布时间】:2018-01-26 20:04:48
【问题描述】:
我正在尝试创建一个计算函数,可以通过“警报”过滤掉我的对象,
所以我创建了一个计算函数,称为 filteredAlarms,并在我的循环中执行 v-for 循环:
<li class="event-log__item timeline__item" v-for="(item, key) in filteredAlarms" :key="key">
在我的过滤器中,我尝试执行以下操作:
let filteredAlarms = Object.keys(this.eventLog).forEach(key => {
this.eventLog[key].filter(item => {
return item.type.indexOf("alarm") > -1
});
});
return filteredAlarms
不幸的是,这不起作用 - 我收到一个错误:TypeError: this.eventLog.filter is not a function
我做错了什么? :)
我试图过滤的对象类似于以下对象:
"system_events": {
"1013": [{
"id": 25899,
"timestamp": "2017-08-15T21:26:42Z",
"type": "alarm",
"code": 190,
"title": "",
"description": "",
"appeared": "2017-08-15T21:26:40Z",
"disappeared": null,
"acknowlegded": null,
"solved": null,
"system_name": "Randers pr 44b sidste station"
},
{
"id": 26157,
"timestamp": "2017-08-15T21:32:17Z",
"type": "warning",
"code": 190,
"title": "",
"description": "",
"appeared": "2017-08-15T21:32:06Z",
"disappeared": null,
"acknowlegded": null,
"solved": null,
"system_name": "Randers pr 44b sidste station"
},
{
"id": 26387,
"timestamp": "2017-08-15T21:37:38Z",
"type": "info",
"code": 190,
"title": "",
"description": "",
"appeared": "2017-08-15T21:37:33Z",
"disappeared": null,
"acknowlegded": null,
"solved": null,
"system_name": "Randers pr 44b sidste station"
}],
"1015": [{
"id": 23777,
"timestamp": "2017-08-15T20:38:08Z",
"type": "alarm",
"code": 191,
"title": "",
"description": "",
"appeared": "2017-08-15T20:38:00Z",
"disappeared": null,
"acknowlegded": null,
"solved": null,
"system_name": "Favrskov Svenstrup gyvelvej"
},
{
"id": 23779,
"timestamp": "2017-08-15T20:38:08Z",
"type": "alarm",
"code": 190,
"title": "",
"description": "",
"appeared": "2017-08-15T20:37:58Z",
"disappeared": null,
"acknowlegded": null,
"solved": null,
"system_name": "Favrskov Svenstrup gyvelvej"
},
{
"id": 23841,
"timestamp": "2017-08-15T20:39:41Z",
"type": "alarm",
"code": 192,
"title": "",
"description": "",
"appeared": "2017-08-15T20:39:31Z",
"disappeared": null,
"acknowlegded": null,
"solved": null,
"system_name": "Favrskov Svenstrup gyvelvej"
},
{
"id": 25243,
"timestamp": "2017-08-15T21:12:03Z",
"type": "alarm",
"code": 191,
"title": "",
"description": "",
"appeared": "2017-08-15T21:11:55Z",
"disappeared": null,
"acknowlegded": null,
"solved": null,
"system_name": "Favrskov Svenstrup gyvelvej"
},
{
"id": 25529,
"timestamp": "2017-08-15T21:18:11Z",
"type": "alarm",
"code": 190,
"title": "",
"description": "",
"appeared": "2017-08-15T21:18:00Z",
"disappeared": null,
"acknowlegded": null,
"solved": null,
"system_name": "Favrskov Svenstrup gyvelvej"
}]
}
【问题讨论】:
标签: javascript ecmascript-6 vue.js