0

I'm using the angularjs-dropdown-multiselect.js to create a multi-select drop-down. I'm trying to dynamically populate the drop-down with existing data from mysql database. If I hardcode the array of objects in my scope, the drop-down is populated correctly and the glyphicon checks are highlighted, as being checked, and the correct numbers are selected. If I pass in the array of objects from the database, as a variable to the scope, the glyphicon checks are not highlighted next to the selected choices, but the correct number of selected is correct. Any ideas on how to fix this? Here is a link to the code I'm using: http://dotansimha.github.io/angularjs-dropdown-multiselect/#/.

1 Answer 1

-1

In the backend, wherever you perform the query to get the array of items from the database, try making a loop that will go through the returned items, and push them into an array, one by one.

then make a get call that will receive array as a response from the database.

I hope this is what you work looking for!

Sign up to request clarification or add additional context in comments.

6 Comments

When I save the initial results, I save them in a MySQL database field as a string, since the number can change depending on the user. Example: [{id: 1}, {id: 3}]. Then when I pull the data, I convert the string to an array of objects, in JavaScript. It shows the correct number of selected on the drop-down, but the checks are not, checked, by the ones that are supposed to be selected.
Could be an issue with your model then, did you check that?
Would be really helpful if you can post some code, or a plunkr
$scope.exampleData.fruits -- This is the string from the database. I pass it into this javascript to convert to an array of objects. Example: [{id: 1}, {id: 3}] var array = []; var tar = $scope.exampleData.fruits.replace(/^\{|\}$/g,'').split(','); for(var i=0,cur,pair;cur=tar[i];i++){ array[i] = {}; pair = cur.split(':'); array[i][pair[0]] = /^\d*$/.test(pair[1]) ? +pair[1] : pair[1]; }
(Both are exactly shown as [object Object],[object Object]) $scope.example6model = array; -- This correctly shows the number of selected, but no glyphions are checked. $scope.example6model = [{id: 1}, {id: 3}]; -- This correctly shows the number of selected and glyphions are checked. $scope.example6settings = {}; $scope.example6data = [{id:1, label: "Apple"}, {id:2, label: "Peach"}, {id:3, label: "Orange"}]; <div selected-model="example6model" options="example6data" ng-dropdown-multiselect="" extra-settings="example6settings"></div>
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.