javascript - Filtering in Vue, nested array -
im trying create computed function can filter out object "alarms",
so i've created computed function, called filteredalarms, , in loop im doing v-for loop:
<li class="event-log__item timeline__item" v-for="(item, key) in filteredalarms" :key="key">
and in filter im trying following:
let filteredalarms = object.keys(this.eventlog).foreach(key => { this.eventlog[key].filter(item => { return item.type.indexof("alarm") > -1 }); }); return filteredalarms
unfortunately, doesn't work - im getting error: typeerror: this.eventlog.filter not function
what doing wrong? :)
the object im trying filter similar 1 below:
"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" }] }
with foreach don't filter anything, iterate. , filter inside returns new array, doesn't change eventlog[key]
.
try instead:
let filteredalarams = {} object.keys(this.eventlog).foreach(key => { filteredalarams[key] = this.eventlog[key].filter(item => { return item.type.indexof("alarm") > -1 }); }); return filteredalarms
Comments
Post a Comment