我正在放置一个从邮政编码在半径上工作的商店查找程序。我已经使用标准查询和QoQ完成了很多次,但现在试图使用cf9 ORM将它们放在一起......但似乎已经达到了我最后一点的能力极限。ORM实体 - 删除记录,并添加一个属性
我拉出一个实体并处理它。最后,我需要:
a。如果记录不符合特定标准(距离大于用户指定的范围),请删除记录
或b。将新属性添加到记录中以存储距离。
因此,最后,我想要的实体是那些在用户指定的范围内的商店,每个记录都包含计算的距离。看什么,我试图做
最好的办法是查看完整的功能
任何建议,不胜感激!
public function getByPostcodeRadius(required postcode="",
required radius=""){
//set some initial vals
rs = {};
geo = New _com.util.geo().init();
local.postcodeGeo = geo.getGeoCode("#arguments.postcode#, Australia");
local.nearbyStores = "";
local.returnStores = {};
//load stores
local.stores = entityload("stores");
//loop over all stores and return list of stores inside radius
for(i=1; i <= ArrayLen(local.stores); i++){
store = {};
store.id = local.stores[i].getID();
store.geoCode = local.stores[i].getGeoCode();
store.Lat = ListgetAt(store.geoCode,1);
store.Lng = ListgetAt(store.geoCode,2);
distance = geo.getDistanceByGeocode(local.postcodeGeo.Lat,local.postcodeGeo.Lng,store.Lat,store.Lng);
//************************
//HERE IS WHERE I AM STUCK.
if (distance LT arguments.radius){
//here I need to add a property 'distance' and set it's value
local.stores[i].distance = distance; // this adds it to the object, but not with the PROPERTIES
} else {
// here i need to remove the store from the object as it's distance was greater than the one passed in
arrayDeleteAt(local.stores,i); //this clearly isn't working, as positions are changing with each loop over
}
}
return local.stores;
}
CF Simplicty ..这工作,好像我要采取的办法,但我似乎无法找到一种方法,命令由“距离”的结果。我可以使用由EntityLoad()返回的对象,但似乎无法解决当我将数组放到此过程的后面时如何排序结果。我玩过ArraySort(),但这并不能解决问题。任何指针?再次感谢CfSimplicity! – Jason 2012-03-18 13:06:49
我最终用这个cflib udf(http://cflib.org/udf/ArrayOfStructsSort)排序..所有的作品都是一种享受。非常感谢您的帮助!! – Jason 2012-03-18 13:17:54
杰森最后非常高兴。毕竟,一个简单的结构或二维数组可能会更容易。顺便说一句,我已经纠正了我的代码中的几个无与伦比的变量:地理应该被引用为local.geo。 – CfSimplicity 2012-03-18 16:32:48