我想要当一个人改变先前绑定复选框的状态时,我想用新值更新服务器。 因此,这里是我:淘汰赛复选框绑定,自动更新
JSCRIPT
function JobViewModel() {
var self = this;
var baseUri = '/Api/Pedidos/';
self.TotalItems = ko.observable(@Model.TotalItems);
self.AbreviaNome = ko.observable(@Model.AbreviaNome.ToString().ToLower());
self.AbreviaFantasia = ko.observable(@Model.AbreviaFantasia.ToString().ToLower());
self.update = function() {
alert('Boom');
$.ajax({
type: "PUT",
url: baseUri,
data: self.Job,
datatype: "json",
contenttype: "application/json"
})
.done(function (data) {
//handleSuccessFunctionHERE(data);
alert('Magic');
})
.error(function (jqXHR, textStatus, errorThrown) {
alert(errorThrown);
alert("fail");
});
};
}
function JobDetailsViewModel() {
var self = this;
var baseUri = '/Api/Pedidos/';
self.Job = new JobViewModel();
}
HTML
<label class="btn btn-primary" data-bind="css: {active:Job.AbreviaNome }">
<input type="checkbox" data-bind="checked: AbreviaNome , onchange: Job.update" name="type" id="AbreviaNome "> Nome</input>
</label>
这从来没有触发更新功能。我也试过:
<label class="btn btn-primary" data-bind="css: {active:Job.AbreviaNome }">
<input type="checkbox" data-bind="checked: AbreviaNome , click: Job.update" name="type" id="AbreviaNome "> Nome</input>
</label>
而且这个JobViewModel内:
this.AbreviaNome.subscribe(function (newValue) {
alert('test');
}, this);
任何想法?
避免使用更改事件绑定。你不需要它。你应该改变淘汰赛的方式 - 使用订阅。 –
我正在尝试,但它不工作,它不会失败,或任何事情。当我在subscribe方法上放置一个断点时,它永远不会触发 – Oakcool