在djang中选择2个多选

2024-10-03 06:20:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我的Select2下拉列表有一些问题。 我最初只需要在我的drop dpwn上选择一个项目,但现在我需要将它作为一个多个字段,所以Select2似乎是最好的选择。在

这是我的原始代码

JS公司

 $.get('/api/foos', function (response){
        $.each(response.foos, function(){
            $('#foo').append('<option>'+this+'</option>')
        })
    })

美国石油学会

^{pr2}$

这对单选很有效。 现在我正试图转换为Select2,但我用它遇到了麻烦 我好像在下拉列表中找不到任何结果

$.get('/api/foos', function (response){
        $("#set_foo").select2({
            multiple:true,
            placeholder: "Select foos"});
            ('response.foos');
    })

并使用相同的api调用


Tags: 项目代码api列表getfooresponsejs
1条回答
网友
1楼 · 发布于 2024-10-03 06:20:25

修好了

$.get('/api/locations', function (response){
        var data = (response.locations)
        console.log(data)
        $("#set_location").select2({
            data: data,
            multiple:true,
            tags:true,
            placeholder: "Select Locations",
        })  
    })

相关问题 更多 >