Backgrid.js根本不工作

时间:2015-01-06 23:49:33

标签: backbone.js backgrid

我很困惑,我做的就像文档一样,但我无法让Backgrid工作。

首先,在我的HTML中引用js:

<script src="{% static 'assets/plugins/jquery-2.1.1.min.js' %}"></script>
<script src="{% static 'extra_js/underscore.js' %}"></script>
<script src="{% static 'extra_js/backbone.js' %}"></script>

<script src="{% static 'Backgrid/lib/backgrid.js' %}"></script>
<script src="{% static 'Backgrid/src/row.js' %}"></script>
<script src="{% static 'Backgrid/src/header.js' %}"></script>
<script src="{% static 'Backgrid/src/preamble.js' %}"></script>
<script src="{% static 'Backgrid/src/formatter.js' %}"></script>
<script src="{% static 'Backgrid/src/footer.js' %}"></script>
<script src="{% static 'Backgrid/src/column.js' %}"></script>
<script src="{% static 'Backgrid/src/cell.js' %}"></script>
<script src="{% static 'Backgrid/src/body.js' %}"></script>

// all of them return 200. Am I missing something here?

然后,JS:

var Note = Backbone.Model.extend({});
var Notes = Backbone.Collection.extend({
    model: Note,
    url: "/../../../sisacademic/notes_api/"
});

var notes = new Notes();
var class_id = "{{class.id}}";
var period_id = "{{period.id}}";

var columns = [{
    name: "name",
    label: "NAME",
    editable: false,
    }, {
    name: "homework",
    label: "Homework",
    cell: "integer"
    },
    {
    name: "individual_activities",
    label: "Individual Activities",
    cell: "integer"
    },
    {
    name: "group_activities",
    label: "Group Activities",
    cell: "integer"
    },
    {
    name: "tests",
    label: "Tests",
    cell: "integer"
    },
    {
    name: "exams",
    label: "Exams",
    cell: "integer"
    }]

var grid = new Backgrid.Grid({
    columns: columns,
    collection: notes
})

$("#grid_notes").append(grid.render().el);

notes.fetch({reset:true, data: {"class": class_id, "period": period_id} });

根本不起作用。它不渲染任何列或单元格,只渲染灰线。 Firebug控制台给了我这些错误:

ReferenceError: root is not defined preamble.js:44:4
TypeError: column.get(...) is not a constructor backgrid.js:1940:0

我必须在此注意到Backgrid的文档记录很少,因此,如果有冒险的开发人员想要使用它,他/她必须准备好在他遇到任何错误时潜入源代码。

无论如何,这是stackoverflow存在的原因之一:它是数千个包的外部资源。所以,如果你可以帮助我,我会很感激。

编辑:

服务器响应是一个像这样的JSON对象:

{&#34; James Logan Wolverine&#34;:{&#34;作业&#34;:12,&#34; group_activities&#34;:15,&#34; individual_activities&#34;:20,& #34;考试&#34;:17,&#34;考试&#34;:16}}

0 个答案:

没有答案