You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Return a sorted version of the source Array. The `sortKey` is the key to use for the sorting. The optional `order` argument specifies whether the result should be in ascending (`order >= 0`) or descending (`order < 0`) order.
2109
+
Return a sorted version of the source Array. You can pass any number of Strings to sort on keys. You can also pass an array containing the sorting keys or a Function if you want to use your own sorting strategy instead. The optional `order` argument specifies whether the result should be in ascending (`order >= 0`) or descending (`order < 0`) order.
2110
2110
2111
-
For arrays of primitive values, any truthy `sortKey`will work.
2111
+
For arrays of primitive values, set `sortKey`to `true`.
2112
2112
2113
2113
-**Example:**
2114
2114
@@ -2165,6 +2165,16 @@ type: api
2165
2165
})
2166
2166
```
2167
2167
2168
+
Sort using two keys:
2169
+
2170
+
```html
2171
+
<ul>
2172
+
<liv-for="user in users | orderBy 'lastName' 'firstName'">
2173
+
{{ user.lastName }} {{ user.firstName }}
2174
+
</li>
2175
+
</ul>
2176
+
```
2177
+
2168
2178
{% raw %}
2169
2179
<divid="orderby-example"class="demo">
2170
2180
<button @click="order = order * -1">Reverse Sort Order</button>
@@ -2185,6 +2195,85 @@ type: api
2185
2195
</script>
2186
2196
{% endraw %}
2187
2197
2198
+
Sort using a Function:
2199
+
2200
+
```html
2201
+
<divid="orderby-compare-example"class="demo">
2202
+
<button@click="order = order * -1">Reverse Sort Order</button>
2203
+
<ul>
2204
+
<liv-for="user in users | orderBy ageByTen">
2205
+
{{ user.name }} - {{ user.age }}
2206
+
</li>
2207
+
</ul>
2208
+
</div>
2209
+
```
2210
+
2211
+
```js
2212
+
newVue({
2213
+
el:'#orderby-compare-example',
2214
+
data: {
2215
+
order:1,
2216
+
users: [
2217
+
{
2218
+
name:'Jackie',
2219
+
age:62
2220
+
},
2221
+
{
2222
+
name:'Chuck',
2223
+
age:76
2224
+
},
2225
+
{
2226
+
name:'Bruce',
2227
+
age:61
2228
+
}
2229
+
]
2230
+
},
2231
+
methods: {
2232
+
ageByTen:function (a, b) {
2233
+
returnMath.floor(a.age/10) -Math.floor(b.age/10)
2234
+
}
2235
+
}
2236
+
})
2237
+
```
2238
+
2239
+
{% raw %}
2240
+
<divid="orderby-compare-example"class="demo">
2241
+
<button @click="order = order * -1">Reverse Sort Order</button>
2242
+
<ulid="orderby-compare-example">
2243
+
<li v-for="user in users | orderBy ageByTen order">
2244
+
{{ user.name }} - {{ user.age }}
2245
+
</li>
2246
+
</ul>
2247
+
</div>
2248
+
<script>
2249
+
newVue({
2250
+
el:'#orderby-compare-example',
2251
+
data: {
2252
+
order:1,
2253
+
users: [
2254
+
{
2255
+
name:'Jackie',
2256
+
age:62
2257
+
},
2258
+
{
2259
+
name:'Chuck',
2260
+
age:76
2261
+
},
2262
+
{
2263
+
name:'Bruce',
2264
+
age:61
2265
+
}
2266
+
]
2267
+
},
2268
+
methods: {
2269
+
ageByTen:function (a, b) {
2270
+
returnMath.floor(a.age/10) -Math.floor(b.age/10)
2271
+
}
2272
+
}
2273
+
})
2274
+
</script>
2275
+
{% endraw %}
2276
+
2188
2277
## Array Extension Methods
2189
2278
2190
2279
Vue.js extends `Array.prototype` with two additional methods that makes it easier to perform some common Array operations while ensuring reactive updates are properly triggered.
0 commit comments