From c32a859bdb93699cc080f9affed4bcff63005a64 Mon Sep 17 00:00:00 2001
From: quazzie
Date: Tue, 14 May 2013 19:56:11 +0100
Subject: feat(select): match options by expression other than object identity
Extend ng-options with a new clause, "track by [trackByExpression]", which can be used when
working with objects. The `trackByExpression` should uniquely identify select options objects.
This solves the problem of previously having to match ng-options objects by identity.
You can now write: `ng-options="obj as obj.name for obj in objects track by obj.id"`
The "track by" expression will be used when checking for equality of objects.
Examples:
scope: {
user: { name: 'Test user', favMovieStub: { id: 1, name: 'Starwars' } }
movies: [{ id: 1, name: 'Starwars', rating: 5, ... }, { id: 13, ... }]
}
The select input will match user favMovieStub to the first movie in the movies array, and show
"Star Wars" as the selected item.
---
src/ng/directive/select.js | 60 ++++++++++++++++++++++++++++++++++++----------
1 file changed, 48 insertions(+), 12 deletions(-)
(limited to 'src')
diff --git a/src/ng/directive/select.js b/src/ng/directive/select.js
index 4f4aace2..7a1cab53 100644
--- a/src/ng/directive/select.js
+++ b/src/ng/directive/select.js
@@ -39,7 +39,7 @@
* * `label` **`for`** `value` **`in`** `array`
* * `select` **`as`** `label` **`for`** `value` **`in`** `array`
* * `label` **`group by`** `group` **`for`** `value` **`in`** `array`
- * * `select` **`as`** `label` **`group by`** `group` **`for`** `value` **`in`** `array`
+ * * `select` **`as`** `label` **`group by`** `group` **`for`** `value` **`in`** `array` **`track by`** `trackexpr`
* * for object data sources:
* * `label` **`for (`**`key` **`,`** `value`**`) in`** `object`
* * `select` **`as`** `label` **`for (`**`key` **`,`** `value`**`) in`** `object`
@@ -59,6 +59,9 @@
* element. If not specified, `select` expression will default to `value`.
* * `group`: The result of this expression will be used to group options using the `