• django + jquery 实现二级联动


    二级联动用ajax还是很好实现的,下面简单给个例子

    jquery代码

    $("#id_sel").change(function(){
        $.get("/browser/gettestcase?type="+cate, function(result){
            //$(".form-control-select").find('[value=header]').remove();
            //$(".form-control-select").selectpicker('refresh');
            if(result.length > 0) {
                 $.each(result,function(index,value){
                     $(".form-control-select").append("<option value='"+value.label+"'>"+value.text+"</option>");
                 })
            }
        }
    )})

    django代码

    def gettestcase(request):
        options_list = []
        cate = request.GET.get('type', 'shop')
        print cate
        options = TestCase.objects.filter(case_category=cate)
        for case in options:
            c = {}
            c['label'] = case.case_name
            c['text'] = case.case_name
            options_list.append(c)      
        return HttpResponse(json.dumps(options_list), content_type='application/json')
  • 相关阅读:
    软件工程第三次作业
    软件工程第一次作业
    软件工程第0次作业
    第2次作业
    第1次作业
    第0次作业
    软件工程第四次作业 石墨文档IOS
    软件工程第三次作业
    软件工程第一次作业
    第零次作业
  • 原文地址:https://www.cnblogs.com/sparkling-ly/p/5508730.html
Copyright © 2020-2023  润新知