以下是聲明和基因敲除的初始化對象淘汰賽編輯工作不
var EmployeeModel = function(data) {
//Make the self as 'this' reference
var self = this;
//Declare observable which will be bind with UI
self.EmployeeID = ko.observable("");
self.FirstName = ko.observable("");
self.LastName = ko.observable("");
var Employee = {
EmployeeID: self.EmployeeID,
FirstName: self.FirstName,
LastName: self.LastName
};
self.Employees = ko.observableArray(data); // Contains the list of employees
self.Employee = ko.observable();
// Edit Employee details
self.edit = function (Employee) {
alert("edit");
self.Employee(Employee);
$("#EmployeePreview").css("display", "none");
$("#PaneEdit").css("display", "block");
}
// Edit Employee details
self.preview = function (Employee) {
alert("preview");
self.Employee(Employee);
$("#PaneEdit").css("display", "none");
$("#EmployeePreview").css("display", "block");
}
// Cancel Employee details
self.cancel = function() {
self.Employee(null);
}
}
$(document).ready(function() {
$.getJSON("/Employee/GetData", null, function (data) {
var viewModel = new EmployeeModel(data);
ko.applyBindings(viewModel);
viewModel.Employee(viewModel.Employees()[0]);
});
});
以下是我的HTML,這是工作的罰款。在編輯的點擊,視圖模型的編輯方法也越來越稱爲
<table cellspacing="10px" border="0">
<tr>
<td width="50%" style="vertical-align:text-top;" >
<table class="List" border="0" cellspacing="4px" cellpadding="4px">
<!---->
<tbody data-bind="foreach: Employees">
<tr>
<td rowspan="2" width="5%"><img src="../../Images/photo.jpg" height="40px" width="40px" alt="Projects" style="cursor:pointer;" onclick=""/></td>
<td width="5%">
<img data-bind="click: $root.preview" src="../../Images/Preview.png" height="16px" width="16px" alt="Projects" style="cursor:pointer;" "/>
</td>
<td data-bind="text: FirstName"></td>
</tr>
<tr>
<td width="5%">
<img data-bind="click: $root.edit" src="../../Images/Edit.png" height="16px" width="16px" alt="Projects" style="cursor:pointer;" onclick="EditEmp();"/></td>
<td data-bind="text: LastName"></td>
</tr>
<!---->
</tbody>
</table>
</td>
但問題是下面由編輯方法聲明中甚至嘗試很多事情
self.Employee(Employee);
可以請人幫我後不工作這 在此先感謝
的onclick刪除,你已經有點擊約束力,沒有定義EditEmp。 – Akhlesh
$ root.edit正在被調用...因爲警報正在顯示。但下面一行是給self self.Employee(Employee);即使刪除EditEmp調用它不起作用 – user3357040