我想在淘汰赛中访问隐藏的字段值 这是我的HTML代码
<td>
<input type="checkbox" data-bind="checked: status, disable: status, click: $root.UpdateStatus" />
<input id="hdnGoalId" type="hidden" data-bind="value: goalId" />
</td>
这是我的javascript代码
var WebmailViewModel = function() {
self.UpdateNote = function () {
$.ajax({
type: "POST",
url: 'SinglePageApp.aspx/UpdateNote',
data: "{goalId: '" + self.goalId + "'}",
contentType: "application/json; charset=utf-8",
success: function (result) {
alert(result.d);
}
});
};
};ko.applyBindings(new WebmailViewModel());
在UpdateNote中,我想传递选定的goalId。 请给我一些建议。
答案 0 :(得分:2)
我看到两个可能的问题
data-bind="value: goalId"
绑定它。请参阅更新的视图模型:
var WebmailViewModel = function() {
var self = this;
self.goalId = ko.observable(10); // where 10 is whatever value goalId should be
self.UpdateNote = function() {
$.ajax({
type: "POST",
url: 'SinglePageApp.aspx/UpdateNote',
data: "{goalId: '" + self.goalId() + "'}",
contentType: "application/json; charset=utf-8",
success: function(result) {
alert(result.d);
}
});
};
};
答案 1 :(得分:0)
感谢您的回复。我通过这样更新获得了解决方案
self.UpdateNote = function (tblUsers) {
$.ajax({
type: "POST",
url: 'SinglePageApp.aspx/UpdateNote',
data: "{goalId: " + tblUsers.goalId + "}",
contentType: "application/json; charset=utf-8",
success: function (result) {
alert(result.d);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
alert(errorThrown);
}
});
};
其中tblUsers是json对象。