//数据常用类
function getArrayDataById(sourceData){

}

function getArrayDataByObject(sourceData,selectObject){
    for (var i=0;i<sourceData.length;i++){
        var currentObj = sourceData[i];
        if(currentObj == selectObject){
            return currentObj;
        }
    }
}
//根据数据属性名属性值获得Object
function getArrayDataByAttribute(sourceData,attributeName,attributeValue){
    for (var i=0;i<sourceData.length;i++){
        var currentObj = sourceData[i];
        if(currentObj[attributeName] == attributeValue){
            return currentObj;
        }
    }
}

function getWhereInConditionByJson(JsonString,attributeName){
    var json = JSON.parse(JsonString);
    var searchWhereStr = "";
    for (var i = 0;i<json.length;i++){
        searchWhereStr += "'"+json[i][attributeName]+"',";
    }
    if(json.length >0){
        searchWhereStr = " "+ attributeName +"  IN ("+searchWhereStr.substr(0,searchWhereStr.length-1)+")";
    }
    return searchWhereStr;
}

//Where IN 条件读取
function getWhereInConditionByArray(sourceData,attributeName){
    var returnStr = "";
    for (var i=0;i<sourceData.length;i++){
        returnStr += "'"+sourceData[i][attributeName]+"',";
    }
    if(sourceData.length >0){
        returnStr = " and OBJECTID IN ("+returnStr.substr(0,returnStr.length-1)+")";
    }
    return returnStr;
}

//判断数据是否为空
function isEmptyValue(value) {
    var type;
    if(value == null) { // 等同于 value === undefined || value === null
        return true;
    }
    if(value == "null"){
        return true;
    }
    type = Object.prototype.toString.call(value).slice(8, -1);
    switch(type) {
        case 'String':
            return !$.trim(value);
        case 'Array':
            return !value.length;
        case 'Object':
            return $.isEmptyObject(value); // 普通对象使用 for...in 判断，有 key 即为 false
        default:
            return false; // 其他对象均视作非空
    }
}

function convertWebserviceResultToArray(){

}

//图层查询结果转换为数组
function convertMapQueryResultToArray(graphics){
    var returnArray = [];
    for(var i = 0; i < graphics.length; i++) {
        var attributes = graphics[i].attributes;
        var addObj = new Object();
        for (var tempObj in attributes){
            addObj[tempObj] = attributes[tempObj];
        }
        addObj.graphic = graphics[i];
        returnArray.push(addObj);
    }
    return returnArray;
}
//Json转换为Array
function convertJsonToArray(JsonString){
    var json = JSON.parse(JsonString);
    return json;
}

//删除重复数据
function unique(arr) {
    var result = [], isRepeated;
    for (var i = 0 ; i < arr.length; i++) {
        isRepeated = false;
        for (var j = 0 ; j < result.length; j++) {
            if (arr[i] == result[j]) {
                isRepeated = true;
                break;
            }
        }
        if (!isRepeated) {
            result.push(arr[i]);
        }
    }
    return result;
}

//遍历Object示例
function foreachObject(Object){
    for (var objName in Object){
        var key = objName;
        var value = Object[objName];
    }
}
