Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 如何在ActionScript 3中替换闭括号和开括号之间的逗号_Mysql_Regex_Actionscript 3_Apache Flex_Esri - Fatal编程技术网

Mysql 如何在ActionScript 3中替换闭括号和开括号之间的逗号

Mysql 如何在ActionScript 3中替换闭括号和开括号之间的逗号,mysql,regex,actionscript-3,apache-flex,esri,Mysql,Regex,Actionscript 3,Apache Flex,Esri,这个问题的基础来自一个FLEX mapping应用程序,在该应用程序中,我使用小部件中的复选框为要素层中提供服务的地理空间数据库中的多个字段生成查询字符串。在程序编译数据库中每个可用字段的每个查询之后,我一直在连接每个查询。在函数的末尾显示如下。以下是循环检查复选框、生成查询字符串并尝试连接查询字符串的函数: public function compileDefexp():void { //conFilter is an HBox that contains the available

这个问题的基础来自一个FLEX mapping应用程序,在该应用程序中,我使用小部件中的复选框为要素层中提供服务的地理空间数据库中的多个字段生成查询字符串。在程序编译数据库中每个可用字段的每个查询之后,我一直在连接每个查询。在函数的末尾显示如下。以下是循环检查复选框、生成查询字符串并尝试连接查询字符串的函数:

public function compileDefexp():void {
    //conFilter is an HBox that contains the available field names in checkboxes.
    var countfilt:uint = conFILTER.numElements;
    var defExpGEO_ACC:String = "";
    var defExpACT_TYP:String = "";
    var defExp:Array = [];

    //clearing filterList on each checkbox click
    filterList = [];

    //loop through the field and field value checkboxes to generate the query strings
    for(var i:int = 0;i < countfilt; i++){
        var childFilter:Object = conFILTER.getElementAt(i);
        var filterName:String = childFilter.name;
        if(childFilter.selected){
            filterList.push(filterName);
            if(filterName == "GEO_ACC"){
                compileValuelistgeo();
                defExpGEO_ACC = "(" + filterName + ") IN (" + qValuelistGEO_ACC + ")";
                defExp.push(defExpGEO_ACC);
            }else if(filterName == "ACT_TYP"){
                compileValuelistact();
                defExpACT_TYP = "(" + filterName + ") IN (" + qValuelistACT_TYP + ")";
                defExp.push(defExpACT_TYP);
            }
        }
    }

    var defExpStr:String = defExp.toString();
    var countfilterList:uint = filterList.length;
    var filterListstr:String = filterList.toString();

    //Cannot get replace the comma between the closed and open parentheses with AND
    //We need to accomplish this to concatenate the query strings for the definition
    //expression to execute correctly.

    //Tried to use RegExp
    var strPattern:RegExp = /\),\(/g;
    var strReplace:RegExp = /\) AND \(/g;

    defExpStr.replace(strPattern, strReplace);

    geoPoints.definitionExpression = defExpStr;

    trace(defExpStr); //(GEO_ACC) IN (GA Value 1,GA Value 2),(ACT_TYP) IN (AT Value 1)

    //We need this to be:
    //(GEO_ACC) IN (GA Value 1,GA Value 2) AND (ACT_TYP) IN (AT Value 1)
}
公共函数compiledFexp():void{
//conFilter是一个HBox,在复选框中包含可用字段名。
var countfilt:uint=conFILTER.numElements;
var defExpGEO_ACC:String=“”;
var defExpACT_TYP:String=“”;
var defExp:Array=[];
//清除每个复选框上的过滤器列表单击
过滤器列表=[];
//循环通过字段和字段值复选框生成查询字符串
对于(变量i:int=0;i
您可以像这样使用替换功能:

    public function replaceExample(str:String, patternOld:String,  patternNew:String):String
    {
        var str2:String = str.replace(patternOld,patternNew);
        return str2;
    }

  //Test result will be:(GEO_ACC) IN (GA Value 1,GA Value 2) AND (ACT_TYP) IN (AT Value 1)

 var str:String = "(GEO_ACC) IN (GA Value 1,GA Value 2),(ACT_TYP) IN (AT Value 1)";
 Alert.show( replaceExample(str, "),(", ") AND (") );

我对if语句进行了一些实验,并利用数组的索引根据所选筛选复选框的数量将查询语句编译在一起。本质上,我们不会试图替换数组中的逗号,而是将每个查询语句与数组的索引号连接起来。下面的代码放在每个查询语句之后已编译querylist:

var defExpStr:String;
if (filterList.length == 1){
    defExpStr = defExp[0];
}else if (filterList.length == 2){
     defExpStr = defExp[0] + " AND " + defExp[1];
}

geoPoints.definitionExpression = defExpStr;
geoPoints.visible = true;

总之,如果您需要一个允许最终用户在数据库中选择多个字段和值并使用复选框配置查询的工具,则此代码可以完成此操作。此代码是专门为ArcGIS API for FLEX开发的,可用于通过ArcServer提供服务的地理空间数据。

出于某种原因,这会产生使用上述代码时,甚至使用.split().join()时,我都会遇到相同的结果。我不确定我们正在编写的代码为什么没有捕获“,”(“。当数组变成字符串时,是否可能会发生奇怪的事情?我知道逗号是将第二个查询字符串推送到数组的结果。似乎definitionExpression方法不接受多个字段上的查询。我直接用添加到小部件中的按钮测试了这一点,并用exactl编码y是我们想要的sql查询。还有其他人经历过吗?