2016-07-29 3 views
0

私は電子商取引のアンドロイドアプリを開発中です。私は複数のフィルタに基づいてアンドロイドのためのdreamfactory APIを使用してレコードを取得しようとしています。私はクラスの外に構築され、パラメータとして提供されているフィルタを使用していたdreamfactory:複数のフィルタでレコードを照会する

public class GetProductsBySubCatIdTask extends BaseAsyncRequest { 

Context context; 
public Products productsRec; 
int subCatId; 
String sort_str,fltr_str; 

public GetProductsBySubCatIdTask(Context context, int subCataId, String sort_str, String fltr_str){ 
    this.context = context; 
    this.subCatId = subCataId; 
    this.sort_str = sort_str; 
    this.fltr_str = fltr_str; 
} 

@Override 
protected void doSetup() throws ApiException, JSONException { 
    callerName = "getProductsBySubCatId"; 

    serviceName = AppConstants.DB_SVC; 
    endPoint = "product"; 
    verb = "GET"; 

    // filter to only select the contacts in this group 

    if(!TextUtils.isEmpty(fltr_str)){ 
      fltr_str = "&&" + fltr_str; 
     } 
     else{ 
      fltr_str = ""; 
     } 

     queryParams = new HashMap<>(); 
     queryParams.put("filter", "sub_category_id=" + subCatId + fltr_str); 
     queryParams.put("order", sort_str); 


     applicationApiKey = AppConstants.API_KEY; 
     sessionToken = PrefUtil.getString(context, AppConstants.SESSION_TOKEN); 

    } 

    @Override 
    protected void processResponse(String response) throws ApiException, JSONException { 
    //Log.d("Tang Ho"," >>>>> " + response); 
    productsRec = 
      (Products) ApiInvoker.deserialize(response, "", Products.class); 
    } 

    @Override 
    protected void onCompletion(boolean success) { 
    if(success && productsRec != null && productsRec.products.size() > 0){ 
     Log.d("Tang Ho"," >>>>> Success"); 
    } 
    } 
} 

GetProductsBySubCatIdTaskとして名前AsyncTaskを使って

、可能なフィルタを使用することができます

unit_offerprice < unit_mrp<br> 
unit_offerprice = unit_mrp<br> 
(unit_offerprice > 200) && (unit_offerprice > 500)<br> 
unit_offerprice > 100<br> 
unit_offerprice < 600<br> 

上記のすべてのフィルタであります単独または2または3の組み合わせで

unit_offerprice < unit_mrp && unit_offerprice > 100 

unit_offerprice%3Cunit_mrp 

ない望ましい結果を得ることができような文字列内のシンボルを脱出した後、 はドキュメンテーションで検索が、見つかった正確な事をdin't。

これにはどのような解決方法がありますか?

答えて

1

フィルタに複数の条件がある場合は、各条件をかっこ()内に配置する必要があります。さらに、ANDでフィルターを結合するための正しい構文は、& &ではなくANDです。 サポートされている論理演算子は、AND、ORおよびNOTです。あなたの例では

、この:

(unit_offerprice < unit_mrp) AND (unit_offerprice > 100) 

ドキュメントのこれらの部分を参照してください: http://wiki.dreamfactory.com/DreamFactory/Features/Database/Records#Filtering_Records http://wiki.dreamfactory.com/DreamFactory/Tutorials/Querying_records_with_logical_filters

DreamFactoryも公式の数を提供しています

unit_offerprice < unit_mrp && unit_offerprice > 100 

は、このする必要がありますユーザーフォーラムを含むサポート・アベニュー。 http://www.dreamfactory.com/support

0

複数のフィルタの括弧を追加して解決しました。

しかし、特殊文字(のような<を、>)を使用して、問題があったと これは、%(<用)3Cと(>用)%の3Eにエンコード

なるために必要な、 に使用される文字列

"(unit_offerprice> 100)および(unit_offerprice < 500)"

符号化された形式である:フィルタリングがある(

」unit_offerprice %3E100)AND(単位:%3C500) "

関連する問題