javascript - Select2 multiple select in django -
i'm having few issues select2 drop-down. needed select 1 item on drop dpwn need have manytomanyfield select2 seemed best option.
here original code
js
$.get('/api/foos', function (response){ $.each(response.foos, function(){ $('#foo').append('<option>'+this+'</option>') }) })
api
@require_get def foos(request): return jsonresponse({ 'foos':[x.foo_name x in foo.objects.all()] }) {foos: ["shh", "fgdh", "fgb", "ghfs", "sfgh", "sfgh", "srth"]}
this worked nicely single selection. trying convert select2, i'm hitting wall cant seem results drop down
$.get('/api/foos', function (response){ $("#set_foo").select2({ multiple:true, placeholder: "select foos"}); ('response.foos'); })
and using same api call
fixed it
$.get('/api/locations', function (response){ var data = (response.locations) console.log(data) $("#set_location").select2({ data: data, multiple:true, tags:true, placeholder: "select locations", }) })
Comments
Post a Comment