mirror of
https://github.com/flarum/framework.git
synced 2025-05-22 22:59:57 +08:00
Add convenience method to get a record by a property
This commit is contained in:
@ -50,6 +50,10 @@ export default class Store {
|
|||||||
return this.data[type] && this.data[type][id];
|
return this.data[type] && this.data[type][id];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getBy(type, key, value) {
|
||||||
|
return this.all(type).filter(model => model[key]() == value)[0];
|
||||||
|
}
|
||||||
|
|
||||||
all(type) {
|
all(type) {
|
||||||
var data = this.data[type];
|
var data = this.data[type];
|
||||||
return data ? Object.keys(data).map(id => data[id]) : [];
|
return data ? Object.keys(data).map(id => data[id]) : [];
|
||||||
|
Reference in New Issue
Block a user