I'm fetching some raw data and displaying a list of items. Each item has a plex property that I generate with a method (which is not a puted property). That property might change on user input. Is it possible to sort the items of the list based on that property?
HTML:
<ul>
<li v-for="item in items">
<span>{{ calculateComplexProperty(item.time) }}</span>
</li>
</ul>
JavaScript:
calculateComplexProperty: function (time) {
// this.distance is an external factor that is not a property of the list item,
// and that can be manipulated by the user
var speed = time * this.distance;
return speed;
}
So each item has a time value that is manipulated by a global, dynamic factor, "distance". The idea is to automatically sort the items whenever the "distance" changes and also, to update the "speed" property. Is this possible?
I'm fetching some raw data and displaying a list of items. Each item has a plex property that I generate with a method (which is not a puted property). That property might change on user input. Is it possible to sort the items of the list based on that property?
HTML:
<ul>
<li v-for="item in items">
<span>{{ calculateComplexProperty(item.time) }}</span>
</li>
</ul>
JavaScript:
calculateComplexProperty: function (time) {
// this.distance is an external factor that is not a property of the list item,
// and that can be manipulated by the user
var speed = time * this.distance;
return speed;
}
So each item has a time value that is manipulated by a global, dynamic factor, "distance". The idea is to automatically sort the items whenever the "distance" changes and also, to update the "speed" property. Is this possible?
Share Improve this question edited May 3, 2017 at 2:17 Garrett Kadillak 1,0609 silver badges18 bronze badges asked May 2, 2017 at 22:36 svensven 5996 silver badges14 bronze badges2 Answers
Reset to default 7How about this?
puted:{
sortedItems(){
return this.items.sort((a,b) =>
this.calculateComplexProperty(a.time) - this.calculateComplexProperty(b.time))
}
}
Template
<li v-for="item in sortedItems">
Template
<li v-for="item in sortedItems(items)">
vue js
puted:{
sortedItems(items){
return _.orderBy(items, 'time', 'asc');
}
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745302965a4621549.html
评论列表(0条)