前端:
<script>
function changeitem(){
var category_name = $("#category_name").val();
$.get("/myadmin/category/getcatename",{category_name:category_name},function(date){
var datalist = date.datalist
var catename = $("#category_item")
catename.empty()
$.each(datalist,function(index,item){
$("<option value='" + item + "'>"+item+"</option>").appendTo(catename)
})
})
}
</script>
后端:
def getcatename(request):
category_name = request.GET.get("category_name")
ob = Category.objects.get(category_name=category_name)
datalist = ob.category_item
datalist = datalist.split("|")
context = {"datalist":datalist}
return JsonResponse(context)