首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使最基本的Backgrid.js示例工作

使最基本的Backgrid.js示例工作
EN

Stack Overflow用户
提问于 2014-04-02 05:04:15
回答 1查看 3.1K关注 0票数 3

我正在试着让backgrid.js最基本的例子开始工作。换句话说,我可以将源文件夹放到xampp/htdocs文件夹中运行,而无需执行任何其他操作。

我已经尝试过许多方法来让代码运行,但我无法得到任何东西来显示。这里是我创建的html页面,它试图看到一个示例工作。

代码语言:javascript
复制
<!DOCTYPE html>
<html>

<head>
    <link rel="stylesheet" href="bootstrap/css/bootstrap.css"/>
    <link rel="stylesheet" href="lib/backgrid.css"/>
    <script src="jquery-1.10.2.min.js"></script>
    <script src="underscore-min.js"></script>
    <script src="backbone-min.js"></script>
    <script src="lib/backgrid.js"></script>
</head>

<body>
<div id="grid">
    <script type="text/javascript">
        var Territory = Backbone.Model.extend({});

        var Territories = Backbone.Collection.extend({
            model: Territory,
            url: "territories.json"
        });

        var territories = new Territories();

        var columns = [{
            name: "id", // The key of the model attribute
            label: "ID", // The name to display in the header
            editable: false, // By default every cell in a column is editable, but *ID* shouldn't be
            // Defines a cell type, and ID is displayed as an integer without the ',' separating 1000s.
            cell: Backgrid.IntegerCell.extend({
                orderSeparator: ''
            })
        }, {
            name: "name",
            label: "Name",
            // The cell type can be a reference of a Backgrid.Cell subclass, any Backgrid.Cell subclass instances like *id* above, or a string
            cell: "string" // This is converted to "StringCell" and a corresponding class in the Backgrid package namespace is looked up
        }, {
            name: "pop",
            label: "Population",
            cell: "integer" // An integer cell is a number cell that displays humanized integers
        }, {
            name: "percentage",
            label: "% of World Population",
            cell: "number" // A cell type for floating point value, defaults to have a precision 2 decimal numbers
        }, {
            name: "date",
            label: "Date",
            cell: "date"
        }, {
            name: "url",
            label: "URL",
            cell: "uri" // Renders the value in an HTML anchor element
        }];

        // Initialize a new Grid instance
        var grid = new Backgrid.Grid({
            columns: columns,
            collection: territories
        });

        // Render the grid and attach the root to your HTML document
        $("#example-1-result").append(grid.render().el);

        // Fetch some countries from the url
        territories.fetch({reset: true});
    </script>
</div>
</body>

</html>

耽误您时间,实在对不起!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-04-07 23:43:56

您似乎在将网格添加到不存在的元素中:

代码语言:javascript
复制
$("#example-1-result").append(grid.render().el);

使用$("#grid")代替,您应该会看到结果。

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22801999

复制
相关文章

相似问题

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