Javascript 基于组合框中选定的默认项目加载排列,并在更改选定项目时重新加载(淘汰)
我想根据组合框中选择的默认项目加载我的页面,并在更改所选项目时重新加载(删除) 目前我正在做的是点击按钮加载表单。这是我的密码。请推荐我,因为我是个新手 html:Javascript 基于组合框中选定的默认项目加载排列,并在更改选定项目时重新加载(淘汰),javascript,jquery,knockout.js,durandal-2.0,Javascript,Jquery,Knockout.js,Durandal 2.0,我想根据组合框中选择的默认项目加载我的页面,并在更改所选项目时重新加载(删除) 目前我正在做的是点击按钮加载表单。这是我的密码。请推荐我,因为我是个新手 html: 更改选定值时,您可以调用加载函数selectedEmployeeList 在构造函数中添加以下代码 this.selectedEmployeeList .subscribe(function(newValue) { //This function is going to get called on every change
更改选定值时,您可以调用加载函数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中的任何内容?我试着把它作为patientsList来创造新的价值,但没有成功。嘿@Dnyanesh,我玩过它,现在它开始工作了。谢谢。不,你不需要在html中做任何更改。
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);
}
};
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);