나는 우편 번호의 반경에서 작동하는 상점 찾기를 구성하고 있습니다. 저는이 표준 쿼리와 QoQ를 사용하여 여러 번 했었지만 이제는 cf9 ORM을 사용하여 하나를 만들려고했습니다 ...하지만 마지막 비트로 내 능력의 한계에 도달 한 것처럼 보였습니다.ORM 엔티티 - 레코드를 제거하고 속성을 추가하십시오.
저는 엔티티를 꺼내 처리 중입니다. 마지막에는 다음을 수행해야합니다.
a. 특정 기준을 충족시키지 못하면 레코드를 제거하십시오 (사용자가 지정한 거리보다 멀음)
OR 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
나는이 cflib udf (http://cflib.org/udf/ArrayOfStructsSort)로 정렬 작업을 끝냈다. 많은 도움을 주셔서 감사합니다 !! – Jason
Jason이 결국 효과가 좋았습니다. 어쩌면 단순한 구조체 또는 2D 배열이 더 쉬울 수도 있습니다. Btw, 내 코드에서 몇 가지 unscoped vars 수정했습니다 : geo local.geo로 참조되어야합니다. – CfSimplicity