我试图用Kendo UI来显示我的模型列表。但它在浏览器控制台给我错误。我把模型列表作为json。请帮我解决这个问题。
模板
$("#grid").kendoGrid({
dataSource: {
type: "odata",
transport: {
read: { //"https://demos.telerik.com/kendo-ui/service/Northwind.svc/Customers"
url: "{% url 'test_json' %}",
dataType: "json",
}
},
schema: {
total: "count",
data: "results",
},
pageSize: 5
},
height: 550,
groupable: true,
sortable: true,
pageable: {
refresh: true,
pageSizes: true,
buttonCount: 5
},
columns: [{
field: "id",
width: 240
}, {
field: "book",
}, {
field: "no_of_page",
}]
});
views.py
def test_json(request):
books = Book.objects.all().values('id','name','no_of_page')
booklist = list(books)
return JsonResponse(booklist, safe=False)
urls.py
url(r'^test/book/$', test_json, name='test_json'),
def test_json(request):
books = Book.objects.all().values('id','name','no_of_page')
booklist = list(books)
content = {
'results' : booklist,
'count' : booklist.count()
}
return JsonResponse(content, safe=False)