Closed airandfingers closed 8 years ago
Apparently, the "optionParser" factory already supports a modelMapper option; in https://github.com/airandfingers/angular-multiselect/commit/9e3ee1641aa31377443b01b04b8edf0640765691 I enabled the use of modelMapper, so that the given expression is used instead of the entire model object.
To use this option, I followed the regular expression in optionParser, and changed options from "t.name for t in tags" to "t._id as t.name for t in tags"
I've tested this briefly without the "t._id as" part included, and it seems to work as before. I don't know whether my change will work in all cases, so for now I'm not going to submit a Pull Request with my change.
@airandfingers Is your pull request accepted? Because I think we have the same problem, we also want the model we bind to contains a list of id strings.. We are also trying to use "t._id as t.name for t in tags" but it always binds our full model to the list.
I'm going to look into this tomorrow and make necessary changes 👍
That would be awesome 👍
@RobbertWolfs So, I just tried c.id as c.name for c in fruits
and it binds id
to the selected. Can you show me an example in plunk?
Please make sure you have latest code. Above plunker is using old codebase.
@amitava82 Let me try to implement it as your example. Otherwise I will try to create a plunker.
Could it be it gives problems with angular 1.5.5? Because we are using the angular components from angular 1.5.x...
I tried to create a gist of all the necessary code https://gist.github.com/RobbertWolfs/4c03ff1a27b042d3fb1d97c1b86445d7
And this is the result we get...
Are you sure that you are using latest version of multiselect lib?
I just did npm install angular-multiselect
ah.. It's old.. Hold on, I'll push latest.
ok thanks
Alright published angular-multiselect@1.2.0
Let me check if I get it to work with the new version.
@amitava82 Thank you it works like a charm 👍 💯
Per the example at http://plnkr.co/edit/LPGYIf?p=preview, I'm using one property of my option objects as the name for the option, with options="t.name for t in tags".
Rather than use the entire option object as a value, I want to only use the _id property, so that the model I bind to contains a list of _id Strings, rather than a list of Objects. This matches my backend, where my MongoDB documents have _id references to other documents.
Is it possible to use a single property as the value of an option, e.g. values="t._id for t in tags"?
My code is live at http://trollsgoals.ayoshitake.com/