gpt4 book ai didi

javascript - 绑定(bind)Kendo网格与数据源不显示数据

转载 作者:行者123 更新时间:2023-11-30 17:35:24 26 4
gpt4 key购买 nike

我正在尝试使用以下引用资料学习 Kendo Grid。

  1. > Grid / Binding to local data
  2. > How to use SetDataSource Method of the Kendo UI Grid
  3. > How-To: Use the DataSource
  4. > How-To: Bind the Grid to Remote Data

我有一个名为“localDataSource”的数据源。网格需要显示来自该源的数据。我尝试在 kendoGrid 定义中定义 dataSource: localDataSource 。然后我尝试显式设置数据源 grid.setDataSource(localDataSource);

尽管没有 javascript 错误,但这两种方法都没有呈现数据。这里缺少什么?

Fiddle

代码

<head>
<title>Grid with DataSource</title>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://cdn.kendostatic.com/2013.2.716/js/kendo.all.min.js"></script>


<style type="text/css">
table, th, td
{
border: 1px solid black;
}
</style>

</head>
<body>


<div id="example" class="k-content">

<div id="grid">
AAAA
</div>

<script>
$(document).ready(function () {

var products = [
{ title: "Nylon", year: 1977 },
{ title: "Fabric Material", year: 1980 },
{ title: "Yards UOM", year: 1983 }
];

var localDataSource = new kendo.data.DataSource({ data: products });

//console.log(localDataSource);

$("#grid").kendoGrid({
dataSource: localDataSource,
height: 430,
columns: [
{ field: "Title", title: "Title", format: "{0:c}", width: "130px" },
{ field: "Year", title: "Year", width: "130px" }
]
});

var grid = $('#grid').data("kendoGrid");
grid.setDataSource(localDataSource);
});
</script>

</div>


</body>

最佳答案

您对列的定义有误。字段选项区分大小写,您使用的是大写字母而不是小写字母。

columns: [
{ field: "title", title: "Title", format: "{0:c}", width: "130px" },
{ field: "year", title: "Year", width: "130px" }
]

Fiddle

关于javascript - 绑定(bind)Kendo网格与数据源不显示数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22152009/

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