由于某些原因,当我使用data-bind =“with:detailedStudent”时,jQuery change()绑定不会被调用。我动态地填充选择选项,但我不确定这应该重要。这是一些我使用的只是尽量给怎么回事的体面图片代码:knockout.js data-bind'with'与jQuery change事件冲突
var viewModel;
$(document).ready(function() {
viewModel = new StudentViewModel();
ko.applyBindings(viewModel);
// this change event is not getting called, but if i put the onchange directly into the html as an attribute, it works fine.
$("#accountDialog").find("#mySelect").change(function() {
alert('hi');
}
}
function Student(data) {
var self = this;
ko.mapping.fromJS(data, {}, this);
}
function StudentViewModel() {
var self = this;
this.students = ko.observableArray([]);
this.detailedStudent = ko.observable();
}
<div id="accountDialog" class="modal hide fade" data-bind="with: detailedStudent">
<select id="mySelect" name="mySelect" data-bind="value: GraduationClassId"></select>
</div>
是的,这确实是......这是我补充的内容:this.GraduationClass.GraduationClassId.subscribe(函数(){ 警报( '你好'); }); –