How to load pre selected items of a jquery selectable
I am currently using a jquery selectable which stores values to a database i would like to create a view page where the users can view which elements were selected.
I was given the following code
- $(function() {
- $("#selectable").selectable({
- create: function( event, ui ) {
- var list=JSON.parse(localStorage.selectableList)
- $(this).children().filter(function(){
- return $.inArray($(this).text(),list) !== -1
- }).addClass("ui-selected")
- },
- stop: function(event, ui) {
- var list = $(".ui-selected", this).map(function() {
- return $(this).text()
- }).get()
- localStorage.selectableList = JSON.stringify(list)
- }
- })
- });
Problem is i am unable to get the values of that i am passing to from the database to load so for e.g. if i have the values 1,2,3,4,5 saved in the database i have the values passed to an array or a string value seperated by , how can i get these values to be pre-selected?