根据组合框中选择的默认项目加载 Spread 并在更改所选项目时重新加载(敲除)
Load Spread based on default item selected in the combobox and reload on changing selected item (knockout)
我想根据在组合框中选择的默认项目加载我的页面,并在更改所选项目(剔除)时重新加载。
目前我正在做的是通过单击按钮加载表单。这是我的代码。请推荐我,因为我是淘汰赛的新手。
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);
}
};
您可以在更改所选值 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);
subscribe :- 是 knockout 提供的工具,它跟踪订阅变量中所做的每个更改并在每次更改时调用函数。
我想根据在组合框中选择的默认项目加载我的页面,并在更改所选项目(剔除)时重新加载。
目前我正在做的是通过单击按钮加载表单。这是我的代码。请推荐我,因为我是淘汰赛的新手。
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);
}
};
您可以在更改所选值 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);
subscribe :- 是 knockout 提供的工具,它跟踪订阅变量中所做的每个更改并在每次更改时调用函数。