我正在尝试在微风中使用执行本地功能,它给我错误'undefined is not a function'。以下是两个函数 - 在第一个函数中,我从数据库中检索数据,在第二个函数中,我尝试从本地缓存中获取数据。
function getServices(clientId, currentLocation, activeStatus) {
var self = this;
var Predicate = breeze.Predicate;
var whereClause = Predicate.create("activeStatus", "==", parseInt(activeStatus));
return EntityQuery.from('Services')
.withParameters({ clientId: clientId, currentLocation: currentLocation })
.where(whereClause)
.expand("Location")
.using(self.manager)
.execute()
.then(querySucceeded, this._queryFailed);
function querySucceeded(data) {
if (data.results.length > 0) {
services = data.results;
}
logSuccess(localize.getLocalizedString('_RetrievedHolidays_'), services, true);
return services;
}
}
function getServicesLocally(clientId, currentLocation, activeStatus, category, type, includeSubLocations) {
var self = this;
services = [];
var Predicate = breeze.Predicate;
var p1 = Predicate.create("activeStatus", "==", parseInt(activeStatus));
var p2 = Predicate.create("fkServiceTypeId", "==", parseInt(type));
var p3 = Predicate.create("fkServiceCategoryId", "==", parseInt(category));
var whereClause = p1;
if (type != 0)
whereClause = whereClause.and(p2);
if (category != 0)
whereClause = whereClause.and(p3);
return EntityQuery.from('Services')
.withParameters({ clientId: clientId, currentLocation: currentLocation })
.where(whereClause)
.orderBy('location.fkLocationTypeId')
.using(self.manager)
.executeLocally()
.then(querySucceeded, this._queryFailed);
function querySucceeded(data) {
if (data.results.length > 0) {
services = data.results;
//if sub-locations are to be ommitted, remove the services of the sub-locations
if (!includeSubLocations) {
services = removeServicesOfSubLocationsFromServiceList(services);
}
}
logSuccess(localize.getLocalizedString('_RetrievedHolidays_'), services, true);
return services;
}
}
以下是检索服务的API调用:
[HttpGet]
public IQueryable Services(int clientId, int currentLocation)
{
locationsRepo = new ClientLocationsRepository(this.CurrentUser, this.SystemContextProvider, clientId);
serviceRepo = new ClientServiceRepository(this.CurrentUser, this.SystemContextProvider, clientId);
int currentLocationType = locationsRepo.GetLocationType(currentLocation).LocationTypeId;
List<Location> accessibleLocationList = GetLocationsAccessible(clientId, currentLocation).ToList();
IQueryable productsAndServices = serviceRepo.GetProductsAndServices(accessibleLocationList, currentLocationType);
return productsAndServices;
}
答案 0 :(得分:1)
因为您在本地查询缓存所使用的方法是给出错误“undefined is is a function”。在本地查询缓存时使用此方法
manager.executeQuery(query).then(function(data) {
var query2 = query.where(predicate)
.using(breeze.FetchStrategy.FromLocalCache);
manager.executeQuery(query2).then(function(dataSubset) {
// use your datasubset to populate your results....
});