我想知道如何从可观察数组中获取对象项(LicenseNo)。我在下面粘贴了我的代码,在插入断点后,我注意到我正在获取整个对象数组,如[LicenseNo,name,assigned route,licenseDate]我只想获得LicenseNo
function getDriverList(item) {
if (!pageViewModel.isAuthenticated()) return;
var dfd = jQuery.Deferred();
var LicenseNo = ko.observableArray([]);
$.when(getSecureData("/api/FleetDrivers/" + item.NationalID))
.done(function (resp) {
pageViewModel.vehicelDriversVM.DriverList(resp.FleetDriverList);
if (pageViewModel.vehicelDriversVM.DriverList(resp.FleetDriverList).length > 0) {
LicenseNo = pageViewModel.vehicelDriversVM.FleetDriverList()[0];
alert('The first driver's License Number is ' LicenseNo;
}
});
return dfd.promise();
}
上面的代码没有用,所以我在下面贴了正确的代码给任何可能遇到类似问题的人
function getDriverList(item) {
if (!pageViewModel.isAuthenticated()) return;
var dfd = jQuery.Deferred();
var LicenseNo = ko.observableArray();
$.when(getSecureData("/api/FleetDrivers/" + item.NationalID))
.done(function (resp) {
pageViewModel.vehicelDriversVM.DriverList(resp.FleetDriverList);
LicenseNo = resp.FleetDriverList[1];
alert('The first driver's License Number is ' + LicenseNo);
});
return dfd.promise();
在这里输入代码