我试图从json数组中提取一个元素并将其分配给一个observable,这样当它的值在下拉列表中发生变化时,observable的值也会随着选择而改变。 observable必须取用户所做的任何选择的值,例如,如果用户选择不同的驱动程序名称,则可以更改驱动程序名称observable。这是我到目前为止所拥有的
索引页
function PageViewModel() {
var pvm = this;
pvm.loginVM = new LoginViewModel();
pvm.VehicleVM = new vehicleViewModel();
pvm.topManagerVM = new TopManagerViewModel();
}
pageViewModel = new PageViewModel();
ko.applyBindings(pageViewModel, document.getElementById("htmlTop"));
vehicle.js =>我的实际问题在哪里
function DriverViewModel() {
var drv = this;
drv.driverId = ko.observable(0);
drv.driverName = ko.observable("");
}
function vehicleViewModel{
vvm.regNumber = ko.observable(0);
vvm.make = ko.observable("");
vvm.model = ko.observable("");
vvm.model = ko.observable("");
vvm.DriverDetail = new DriverViewModel();
}
function getDrivers(id) {
if (!pageViewModel.isAuthenticated()) return;
$.when(getSecureData("/api/vehicleDrivers/" + id))
.done(function (driverList) {
driverList.unshift({ "driverId": 0, "driverName": "Please select a driver..." });
pageViewModel.DriverVM.driverList(driverList);
var List = driverList;
List[0] = pageViewModel.VehicleVM.driverDetail.driverId;
List[1] = pageViewModel.vehicleVM.driverDetail.driverName;
})
.fail(function (message) {
$.msgbox(message);
});
}