myforce / angularjs-dropdown-multiselect

AngularJS Dropdown Multiselect
http://myforce.github.io/angularjs-dropdown-multiselect/
MIT License
34 stars 28 forks source link

Use array of strings for options instead of array of objects? #41

Closed atentis closed 7 years ago

atentis commented 7 years ago

See title. I would like to just use a simple string array but am not seeing how in the documentation. Is this possible? I do not have Ids and would over complicate things.

This: scope.options= ["David", "Jhon", "Danny"]; Instead of this: scope.options= [{ id: 1, label: "David" }, { id: 2, label: "Jhon" }, { id: 3, label: "Danny" }];

Thanks!

pkempenaers commented 7 years ago

If you could use: scope.options= [{ label: "David" }, { label: "Jhon" }, { label: "Danny" }]; and set idProp to label you don't need to generate ids. If that doesn't suffice I'll make this issue into a feature request at https://github.com/dotansimha/angularjs-dropdown-multiselect/issues (I'm a contributor at that repo) know however that the backlog is long.

atentis commented 7 years ago

Ok I will use idProp for now but will put in a feature request for future use. It would be really helpful.

Thanks!

alkeshattal commented 7 years ago

Incase the options list is not fixed, but infact a REST resource, we cannot change the producer to tailor the JSON in our required format. This I think needs to be taken up so as to handle simple list of array.

alkeshattal commented 7 years ago

You may try out using below check... if (angular.isString(item)) { return item; } else if (angular.isObject(item)) { // do as it is currently being done }

pkempenaers commented 7 years ago

If you want to implement this go ahead and make a PR, I however think that a array of strings can always be converted to objects and then the selection can be converted back to plain strings and as such this issue has a "good" workaround and there are more important issues to be fixed.