单击 Add Another 按钮后,我需要启用 Save Changes 和 Cancel Changes 按钮。Save Changes 按钮和 Cancel Changes 按钮在页面加载时已被禁用,但由于某种原因在单击通过时不会启用。
{$().ready(function () {
$("#tabs").tabs();
$("#cancel-default").button().attr('disabled',true).addClass('ui-state-disabled');
$("#add-default").button();
$("#show-default-entry").button();
$("#save-all-defaults").button().attr('disabled', true).addClass('ui-state-disabled');
$(".ko-remove-link").button();
$("#saved-dialog-message").dialog({
autoOpen: false,
modal: true,
buttons: {
Ok: function () {
$("#saved-dialog-message").dialog('close');
}
}
});
var AdjustmentsViewModel = function() {
var self = this;
// properties
self.EmployeeId = $("#BaseEmployeeId").val();
self.Adjustments = ko.observableArray(initialData);
// methods
self.add = function (incoming) {
self.Adjustments.push(incoming);
};
self.remove = function (adjustment) {
self.Adjustments.remove(adjustment);
};
self.save = function () {
$.ajax({
url: '/Employee/AddAdjustmentDefaults',
crossDomain: true,
data: ko.toJSON(self),
contentType: "application/json; charset=utf-8",
dataType: 'json',
type: 'POST',
success: function (data) {
$("#saved-dialog-message").dialog("open");
},
error: function (error) { alert("Error."); },
always: function () { }
});
};
}
var viewModel = new AdjustmentsViewModel();
ko.applyBindings(viewModel);
$("#cancel-default").click(function () {
$("#show-default-entry").prop("disabled", false);
$("#entry-row").hide();
});
$("#show-default-entry").click(function () {
$("#show-default-entry").prop("disabled", true);
$("#entry-row").show();
});
$("#add-default").button().click(function () {
var record = {
"Id": "0",
"EmployeeId": $("#EmployeeId").val(),
"AdjustmentTargetTypeId": $("#TargetTypeId option:selected").val(),
"AdjustmentTargetId": $("#TargetId").val(),
"AdjustmentTargetTypeDescription": $("#TargetTypeId option:selected").text(),
"AdjustmentTargetDescription": $("#TargetId option:selected").text(),
"Amount": $("#Amount").val()
};
viewModel.add(record);
$("#show-default-entry").prop("disabled", false);
$("#entry-row").hide();
});
});
}