Skip to content
This repository has been archived by the owner on Oct 2, 2019. It is now read-only.

Using objects in <ui-select-choices repeat=""> #971

Closed
blowsie opened this issue May 28, 2015 · 5 comments
Closed

Using objects in <ui-select-choices repeat=""> #971

blowsie opened this issue May 28, 2015 · 5 comments

Comments

@blowsie
Copy link

blowsie commented May 28, 2015

Forgive me if this has already been asked, I couldn't find a ticket for it.

I'm migrating from ui-select2, which allowed me to use objects as my data for example:

var data = {
    'Adam': {
        age: 10,
        location: 'UK'
    }
}

HTML
<select data-ng-options="value as key for (key, value) in data">

How can I use an object as my data in ui-select?
I tried data-repeat="name in data" but got [ui.select:items] Expected an array but got {"Adam"...

@Andrewpk
Copy link

👍trying to find information on the same thing right now.

@blowsie
Copy link
Author

blowsie commented Jun 3, 2015

@Andrewpk did you manage to figure out a solution? Changing the object to an array is a last resort for me for performance reasons.

@Andrewpk
Copy link

Andrewpk commented Jun 3, 2015

I just ended up switching to angular-chosen which supports both arrays and objects as data sources.

On Jun 3, 2015, at 8:13 AM, Sam Blowes notifications@github.com wrote:

@Andrewpk did you manage to figure out a solution? Changing the object to an array is a last resort for me for performance reasons.


Reply to this email directly or view it on GitHub.

@akotlar
Copy link

akotlar commented Jun 3, 2015

Agreed, I think this is a major limitation. The source clearly expects items to be in the

"item in array" with an optional track by: see line 1774

var match = expression.match(/^\s_(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s_$/);

This can be changed to

var match = expression.match(/^\s_(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+._\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);

and will pick up matches, but further modifications are needed in order to return items, haven't looked into it any further.

It wold be really useful to allow standard ng-options syntax; this seems like a major limitation.

@dimirc
Copy link
Contributor

dimirc commented Sep 27, 2015

PR #1208 should resolve this

@dimirc dimirc closed this as completed Sep 29, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants