我是 MVC4 和淘汰赛的新手。我从网格开始。所以我从这个 URL 复制了所有内容:http: //knockoutjs.com/examples/grid.html
所以这是我的js文件。
$(document).ready(function () {
ko.applyBindings(new PagedGridModel(initialData));
});
var initialData = [
{ name: "Well-Travelled Kitten", sales: 352, price: 75.95 },
{ name: "Speedy Coyote", sales: 89, price: 190.00 },
{ name: "Furious Lizard", sales: 152, price: 25.00 },
{ name: "Indifferent Monkey", sales: 1, price: 99.95 },
{ name: "Brooding Dragon", sales: 0, price: 6350 },
{ name: "Ingenious Tadpole", sales: 39450, price: 0.35 },
{ name: "Optimistic Snail", sales: 420, price: 1.50 }
];
var PagedGridModel = function (items) {
this.items = ko.observableArray(items);
this.gridViewModel = new ko.simpleGrid.viewModel({
data: this.items,
columns: [
{ headerText: "Item Name", rowText: "name" }
],
pageSize: 4
});
};
这是我的cshtml
<link href="../../Content/list/list.css" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/jquery-1.6.2.min.js")" type="text/javascript"> </script>
<script src="../../Scripts/knockout-1.3.0beta.js" type="text/javascript"></script>
<script src="../../Scripts/list/list.js" type="text/javascript"></script>
<div class='liveExample'>
<div data-bind='simpleGrid: gridViewModel'> </div>
<button data-bind='click: addItem'>
Add item
</button>
<button data-bind='click: sortByName'>
Sort by name
</button>
<button data-bind='click: jumpToFirstPage, enable: gridViewModel.currentPageIndex'>
Jump to first page
</button>
</div>
“ko.simpleGrid”正在变得未定义,所以它说 * can not read property 'viewModel' of undefind *。可能是什么原因?
谢谢你的帮助。