我正在尝试使用带有KO绑定的表。通过遵循本教程http://knockoutjs.com/examples/grid.html中的示例,我已经为此变量创建了一个网格。
var PagedGridModel = function(items) {
this.items = ko.observableArray(items);
this.gridViewModel = new ko.simpleGrid.viewModel({
data: this.items,
columns: [
{ headerText: "Date Created", rowText: function (response) {
var d = new Date(response.postingDate);
return d.toLocaleDateString();
} },
{ headerText: "Subject", rowText: "subject" },
{ headerText: "Status", rowText: "status" },
{ headerText: "Date Updated", rowText: function (response) {
var d = new Date(response.updationDate);
return d.toLocaleDateString();
} },
{ headerText: "", rowText: function (response) { } }
],
pageSize: 10
});
};
我需要在最后一行rowText中编写一个函数来为我的页面创建一个超链接。这是我试图用Knockout取代的JSP。
<c:forEach items="${responses}" var="response">
<tr>
<td>${response.postingDate}</td>
<td>${response.subject}</td>
<td>${response.status}</td>
<td>${response.updationDate}</td>
<c:url value="/contact/viewDetails" var="viewDetailsURL">
<c:param name="ticketId" value="${response.ticketID}"/>
</c:url>
<td><a href="${viewDetailsURL}">View Details</a></td>
</tr>
</c:forEach>
如何在最后一个rowText函数中为“View Details”创建一个href?
答案 0 :(得分:0)
你必须像这样使用attr binding
<a data-bind="attr:{href: '${viewDetailsURL}'}">View Details</a>