1 Reply Latest reply on Dec 26, 2007 4:17 PM by Tariq Ahmed [ACP]

    Filter RemoteObject result

    pope on acid Level 1
      I try to run a filter on a RemoteObject result array, but it won't filter.
      Code won't work, I cleaned it up and just kept the relevant codelines.
      <mx:Script>
      <![CDATA[
      [Bindable]
      private var catalog:ArrayCollection;

      private function initApp():void
      {
      productService.getAanbiedingen();
      }

      public function productServiceResultHandler(event:ResultEvent):void
      {
      // Remote Service returns an ArrayCollection
      var products:ArrayCollection = event.result as ArrayCollection;
      var temp:ArrayCollection = new ArrayCollection();
      var cursor:IViewCursor = products.createCursor();
      while (!cursor.afterLast)
      {
      var product:Product = new Product();
      product.fill(cursor.current);
      temp.addItem(product);
      cursor.moveNext();
      }
      catalog = temp;
      catalog.filterFunction = filterByCategory;
      catalog.refresh();
      }
      //-------------------------------------------------------------------------------
      public function filterByCategory(item:Object):Boolean
      {
      var isMatch:Boolean = false
      var tevergelijken:String = "operations";

      if(tevergelijken.search(item.categories.toLowerCase()) != -1)
      {
      isMatch = true
      }
      return isMatch;
      }
      //-------------------------------------------------------------------------------
      ]]>
      </mx:Script>

      <mx:Style source="blue.css"/>
      <mx:Style source="main.css"/>

      <mx:RemoteObject id="productService" destination="ColdFusion" source="components.BuyAndSell" showBusyCursor="true">
      <mx:method name="getAanbiedingen" result="productServiceResultHandler(event)" fault="Alert.show(event.fault.message)"/>
      </mx:RemoteObject>

      <mx:ViewStack id="storeViews" width="100%" height="550" creationPolicy="all">
      <tabs:Products id="productView" label="BUY IT" catalog="{catalog}" />
      </mx:ViewStack>
      </mx:Application>
        • 1. Re: Filter RemoteObject result
          Tariq Ahmed [ACP]
          A quick guess is that catalog is pointed at temp, and temp exists for the life of your productServiceResultHandler function. So after the function is over, your catalog variable is pointed at null.

          catalog = temp <-- this won't copy temp to catalog, is just points catalog at temp.

          Here's a quick 'n dirty way of doing it:

          <mx:Script>
          <![CDATA[
          import mx.collections.ArrayCollection;
          public var ar1:ArrayCollection;
          public var ar2:ArrayCollection;
          public function yo():void
          {
          ar1 = new ArrayCollection([{b:1,c:2},{b:3,c:4}]);
          ar2 = new ArrayCollection(ar1.toArray());
          }
          ]]>
          </mx:Script>

          Though here's a more hardcore way:
          http://www.cflex.net/showFileDetails.cfm?ObjectID=637