我有一个像这样的网格系统
<div class="section table_section">
<div class="section_inner" id="divTestKoRemoteGrid">
<div class="title_wrapper" data-bind="with: Grid">
<h2 data-bind="text: TotalCount">
Prices</h2>
</div>
<div class="section_content">
<div id="product_list" data-bind="with: Grid">
<!--[if !IE]>start table_wrapper<![endif]-->
<div class="table_wrapper">
<div class="table_wrapper_inner">
<table cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<th>
No.
</th>
<th>
Tier
</th>
<th>
</th>
</tr>
<!-- ko foreach: Data -->
<tr data-bind="css: { second: $index() % 2 }">
<td data-bind="text: Id" style="width: 26px;">
</td>
<td data-bind="text: Tier" style="width: 35px;">
</td>
<td style="width: 120px;">
<div class="actions_menu">
<ul>
<li><a class="edit" href="">edit</a></li>
<li><a class="delete" href="">deny</a></li>
</ul>
</div>
</td>
</tr>
<!-- /ko -->
</tbody>
</table>
</div>
</div>
<!--[if !IE]>end table_wrapper<![endif]-->
</div>
<!-- ko with: Grid -->
<div class="pagination" data-bind="with: Page">
<span class="page_no" data-bind="text: TotalCount"></span>
<ul class="pag_list" data-bind="foreach: ko.utils.range(1, TotalPage)">
<li><a href="" data-bind="click: $parent.Goto, css:{current_page: $data == $parent.CurrentPage}">
<span><span data-bind="text: $data"></span></span></a></li>
</ul>
</div>
<!-- /ko -->
</div>
</div>
</div>
和淘汰视图模型
var my = my || {};
$(function () {
my.PriceListViewModel = (function () {
var
grid = ko.observable(),
loadGrid = function () {
my.ListModel.LoadData();
grid(my.ListModel);
};
return {
Grid: grid,
LoadGrid: loadGrid
};
})();
my.ListModel = (function () {
var
data = ko.observableArray([]),
totalCount = ko.observable(),
page = ko.observable(),
goTo = function (d) {
$.getJSON("/prices/GetByFilterViaJSON?limit=6&page=" + d, function (list) {
data(list.Data);
page(list.Page);
});
},
loadData = function () {
$.ajax({
type: 'GET',
url: '/prices/GetByFilterViaJSON',
dataType: 'json',
success: function (list) {
data(list.Data);
page(list.Page);
totalCount(list.TotalCount);
},
data: { limit: 6 },
async: false
});
};
return {
Data: data,
TotalCount: totalCount,
Page: page,
GoTo: goTo,
LoadData: loadData
};
})();
my.PageModel = (function () {
var
currentPage = ko.observable(1),
totalCount = ko.observable(1),
limit = ko.observable(),
start = ko.observable(),
nextPage = ko.observable(1),
previousPage = ko.observable(1),
totalPage = ko.observable(1),
loadData = function (pageData) {
currentPage(pageData.CurrentPage);
totalCount(pageData.TotalCount);
limit(pageData.Limit);
start(pageData.Start);
nextPage(pageData.NextPage);
previousPage(pageData.PreviousPage);
totalPage(pageData.TotalPage);
};
return {
CurrentPage: currentPage,
TotalCount: totalCount,
Limit: limit,
Start: start,
NextPage: nextPage,
PreviousPage: previousPage,
TotalPage: totalPage,
LoadData: loadData
};
})();
my.PriceListViewModel.LoadGrid();
ko.applyBindings(my.PriceListViewModel);
});
当我尝试执行 GoTo 函数(在 ListModel 中)时,浏览器找不到该函数,并且敲除无法在 click 事件中绑定。
我尝试解决此问题 5 天。你觉得有什么问题?