首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Backgrid无法呈现列

Backgrid无法呈现列
EN

Stack Overflow用户
提问于 2013-02-08 20:21:36
回答 2查看 2.2K关注 0票数 1

我只是在学习backgrid.js的基础知识。因此,当我试图在主页面Backgrid.js上复制代码时,由于传递列的对象数组时出现特定错误,无法呈现网格。我相信我用的是正确的格式

代码语言:javascript
复制
 var columns = [
    { name: "name", label: "Name", cell: "string" },
    { name: "address", label: "Address", cell: "string" },
    { name: "tel", label: "Phone", cell: "integer" },
    { name: "email", label: "Email", cell: "string" },
    { name: "type", label: "Contact Type", cell: "string" }
];

在此步骤初始化网格的过程中,TypeError: Object对象对象没有方法“listenTo”发生错误:

代码语言:javascript
复制
    var grid = new Backgrid.Grid({
        columns: columns,
        collection: this.collection
    });

我如何初始化网格有问题吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-02-11 14:20:43

问题在于我使用的backbone.js版本。我再次推荐使用适当版本的库。

Backgrid.js依赖于3个库来运行: JQuery1.7.0、>= ~ 1.4.0和backbone.js ~ 0.9.10。

票数 2
EN

Stack Overflow用户

发布于 2013-02-08 21:32:46

这是一个关于如何使用它的简单结构。

HTML

代码语言:javascript
复制
<div id="container"></div>

JS

代码语言:javascript
复制
$(function(){
    /** Columns definition */
    var columns = [
    { name: "name", label: "Name", cell: "string" },
    { name: "address", label: "Address", cell: "string" },
    { name: "tel", label: "Phone", cell: "integer" },
    { name: "email", label: "Email", cell: "string" },
    { name: "type", label: "Contact Type", cell: "string" }
    ];

    /** Model instance */
    var mdl = Backbone.Model.extend({});

    /** Collection instance */
    var col = Backbone.Collection.extend({
        model: mdl  
    });

    /** Test array of JSON (usually coming from a server) */
    var json = [
        {"name": "Goose", "address": "a 1st address", "tel": 25500100, "email": "w@test.net","type": 1},
        {"name": "Ducky", "address": "a 2nd address", "tel": 25500123, "email": "w@test1.net","type": 2}
   ];

   /** Create the Grid */
   var grid = new Backgrid.Grid({
      columns: columns,
      collection: new col(json)
   });

   /** Add the Grid to the container */
   $("#container").append(grid.render().$el);
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14780715

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档