2π
β
It looks like your data is an object of key/value pairs. Unfortunately, the majority of browsers donβt support Object.values
which will give you an array of just the values of the object:
return Object.values(this.vehicles) // Array of vehicle objects
.filter(function (v) {
return v.name === ('aaa' || 'bbb')
})
β¦but there is an Object.keys
method which is largely supported, so you can get to the values with a two-step process:
return Object.keys(this.vehicles) // Array of keys in the JSON obj
.map(key => this.vehicles[key]) // Array of vehicle objects
.filter(function (v) {
return v.name === ('aaa' || 'bbb')
})
Or if you want to use something like lodash
, that gives you some more convenient functions for dealing with manipulating objects.
π€Jacob
0π
put this in your app.js file
Vue.filter('snippet',function (val) {
return val.slice(0,100);
})
and when you want to use it just put snippest in your html like this.
<p class="card-text mb-auto">{{product.description | snippet}}</p>
π€Mohammed Aktaa
Source:stackexchange.com