我想根据在组合框中选择的默认项目加载我的页面,并在更改所选项目时重新加载(淘汰赛)。
目前我正在做的是点击按钮加载表单。这是我的代码。请建议我,因为我是淘汰赛的新手。
HTML:
<select data-bind="options : employeeList, optionsText : 'name', value : selectedEmployeeList"></select>
</span>
<button class="toolbar-button" data-bind="click : load, disable :loading">Load employee</button>
JS:
var filterVM = function () {
this.employeeList = ko.observableArray();
this.selectedEmployeeList = ko.observable();
};
dataService.getEmployeeLists(this.viewData.EmployeeId).then(loadEmployeeLists).then(enableControls);
filterVM.prototype.load = function () {
var selectedEmployeeList = this.selectedEmployeeList();
var self = this;
if (selectedEmployeeList) {
disableControls();
dataService.getEmployeeByEmployeeList(this.viewData.employeeId, selectedEmployeeList.id)
.done(loadPEmployeeSpread);
}
};
答案 0 :(得分:1)
您可以在更改所选值selectedEmployeeList时调用您的加载函数 在构造函数
中添加以下代码this.selectedEmployeeList .subscribe(function(newValue) {
//This function is going to get called on every change of the selectedEmployeeList
//Add here your code to load the page
}, this);
订阅: - 是由淘汰赛提供的工具,它跟踪订阅变量中的每个更改,并在每次更改时调用函数。