我一直在玩剑道移动演示,我对其中一个示例感到有些困惑。在这个特定的例子中,有一段 javascript
<script id="hierarchicalMobileListViewTemplate" type="text/x-kendo-template">
# if (data.HasEmployees) { #
<h2> #: FullName # </h2>
</a>
# } else { #
<h2> #: FullName # </h2>
# } #
</script>
其中有data.HasEmployees,我不确定“数据”部分来自哪里,因为它不是代码中任何地方的变量。
这是示例 http://trykendoui.telerik.com/ufup。任何帮助将不胜感激。
谢谢
迈克尔
ps代码完整复制
<!DOCTYPE html>
<html>
<head>
<base href="http://demos.telerik.com/kendo-ui/mobile/listview/hierarchical-databinding.html">
<style>html { font-size: 12px; font-family: Arial, Helvetica, sans-serif; }</style>
<title></title>
<link href="http://cdn.kendostatic.com/2014.1.416/styles/kendo.common.min.css" rel="stylesheet" />
<link href="http://cdn.kendostatic.com/2014.1.416/styles/kendo.default.min.css" rel="stylesheet" />
<link href="http://cdn.kendostatic.com/2014.1.416/styles/kendo.mobile.all.min.css" rel="stylesheet" />
<script src="http://cdn.kendostatic.com/2014.1.416/js/jquery.min.js"></script>
<script src="http://cdn.kendostatic.com/2014.1.416/js/kendo.all.min.js"></script>
</head>
<body>
<div data-role="view" data-show="rebindListView" id="hierarchical-view" data-transition="slide">
<header data-role="header">
<div data-role="navbar" id="employee-navbar">
<a data-role="backbutton" id="employee-back" data-align="left">Back</a>
<span data-role="view-title"></span>
<a data-align="right" data-role="button" class="nav-button" href="#/">Index</a>
</div>
</header>
<ul id="hierarchical-listview" data-role="listview" data-template="hierarchicalMobileListViewTemplate"></ul>
</div>
<script id="hierarchicalMobileListViewTemplate" type="text/x-kendo-template">
# if (data.HasEmployees) { #
<h2> #: FullName # </h2>
</a>
# } else { #
<h2> #: FullName # </h2>
# } #
</script>
<script>
var serviceRoot = "http://demos.telerik.com/kendo-ui/service";
var employees = new kendo.data.HierarchicalDataSource({
transport: {
read: {
url: serviceRoot + "/Employees",
dataType: "jsonp"
}
},
schema: {
model: {
id: "EmployeeId",
hasChildren: "HasEmployees"
}
}
});
function rebindListView(e) {
var parentID = e.view.params.parent,
element = e.view.element,
backButton = element.find('#employee-back'),
listView = element.find("#hierarchical-listview").data('kendoMobileListView'),
navBar = element.find('#employee-navbar').data('kendoMobileNavBar');
if (parentID) {
employees.fetch(function() {
var item = employees.get(parentID);
if (item) {
backButton.show();
navBar.title(item.FullName);
listView.setDataSource(item.children);
} else {
// redirect to root
setTimeout(function() {
kendo.mobile.application.navigate('#hierarchical-view');
}, 0);
}
});
} else {
backButton.hide();
navBar.title('Employees');
listView.setDataSource(employees);
}
e.view.scroller.scrollTo(0, 0);
}
</script>
<script>
var app = new kendo.mobile.Application(document.body);
</script>
</body>
</html>