gpt4 book ai didi

javascript - 让最基本的 Backgrid.js 示例正常工作

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:47:42 24 4
gpt4 key购买 nike

我正在尝试让 backgrid.js 的最基本示例正常工作。换句话说,这是一个我可以将源文件夹放入我的 xampp/htdocs 文件夹并运行而无需执行任何其他操作的示例。

我已经尝试了很多方法来运行代码,但我无法显示任何内容。这是我尝试查看示例工作的 html 页面。

<!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>

感谢您的宝贵时间!

最佳答案

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

$("#example-1-result").append(grid.render().el);

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

关于javascript - 让最基本的 Backgrid.js 示例正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22801999/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com