首页 / 浏览问题 / 云GIS / 问题详情
iclient classic调用数据更新接口时报错
10EXP 2023年04月07日
$(".saveData").click(() => {
    let changeUrl =
        "http://localhost:8090/iserver/services/data-World/rest/data/datasources/World/datasets/Countries";
    let feature = selectResult.features[0];
    console.log(feature);
    let afterChangeData = getTableData();
    console.log(afterChangeData);
    let names = Object.keys(afterChangeData);
    let values = Object.values(afterChangeData);
    console.log(names);
    console.log(values);
    let outFeature = {
        fieldNames: names,
        fieldValues: values,
        geometry: feature.geometry,
    };
    let editFeatureParameter = new SuperMap.REST.EditFeaturesParameters({
        features: [outFeature],
        editType: SuperMap.REST.EditType.UPDATE,
    });
    let editService = new SuperMap.REST.EditFeaturesService(changeUrl, {
        eventListeners: {
            processCompleted: editCompleted,
            processFailed: editFailed,
        },
    });

    editService.processAsync(editFeatureParameter);

    // 处理编辑成功的回调函数
    function editCompleted(editEventArgs) {
        console.log("数据集编辑成功");
    }

    // 处理编辑失败的回调函数
    function editFailed(editEventArgs) {
        console.log(editEventArgs);
        console.log("数据集编辑失败");
    }
});

报错:errorMsg:"the number of 'fieldNames' and 'fieldValues' are not equal"

但是我在负载中查看的传入的这两个参数,他们的number相等呀

[
    "SMID",
    "SMUSERID",
    "SMAREA",
    "SMPERIMETER",
    "SMGEOMETRY",
    "COUNTRY",
    "CAPITAL",
    "COLORID",
    "COLOR_MAP",
    "SQKM",
    "SQMI",
    "POP_1994",
    "CONTINENT"
]

{
    "SMID": "234",
    "SMUSERID": "0",
    "SMAREA": "9.474653104403312E12",
    "SMPERIMETER": "3.0389755757874787E7",
    "SMGEOMETRY": "",
    "COUNTRY": "中国",
    "CAPITAL": "北京",
    "COLORID": "1",
    "COLOR_MAP": "1",
    "SQKM": "9367281.0",
    "SQMI": "3616707.25",
    "POP_1994": "1.128139689E9",
    "CONTINENT": "111"
}

1个回答

您好,fieldValues里只需要有对应的字段值就可以,

比如:

     "fieldNames": [

            "SMID",

            "SMSDRIW",

            "SMSDRIN",

            "SMSDRIE",

            "SMSDRIS",

            "SMUSERID",

            "SMAREA",

            "SMPERIMETER",

            "SMGEOMETRYSIZE",

            "SQKM",

            "SQMI",

            "COLOR_MAP",

            "CAPITAL",

            "COUNTRY",

            "POP_1994",

            "CONTINENT"

        ],

        "fieldValues": [

            "22",

            "-7.433472633361816",

            "62.35749816894531",

            "-6.38972282409668",

            "61.388328552246094",

            "6",

            "0.25430895154659083",

            "5.743731026651685",

            "4500",

            "1474.69",

            "569.38",

            "5",

            "示例首都 a",

            "示例国家 a",

            "47067.0",

            "亚洲"

        ],

希望可以帮助到您。
10,588EXP 2023年04月07日
您好,我试过了,还是相同的报错

现在的数据为

[

    "SMID",

    "SMUSERID",

    "SMAREA",

    "SMPERIMETER",

    "SMGEOMETRY",

    "COUNTRY",

    "CAPITAL",

    "COLORID",

    "COLOR_MAP",

    "SQKM",

    "SQMI",

    "POP_1994",

    "CONTINENT",

];

[

    "234",

    "0",

    "9.474653104403312E12",

    "3.0389755757874787E7",

    "",

    "中国",

    "北京",

    "1",

    "1",

    "9367281.0",

    "3616707.25",

    "1.128139689E9",

    "亚洲",

];

依然会报错errorMsg":"the number of 'fieldNames' and 'fieldValues' are not equal"
建议您核对下,

1.您目前更新的字段是否数据集中都有

2.目前更新的字段是否字段类型本身与您更新是传入的值都匹配,比如整型只能写整数,双精度只能写不超过限度的数字,不含字母字符

属性更新时,只有SMID是必须字段,其它字段并非必须要有,您可以测控制变量,

看看只带那些字段或者不带那些字段更新时会报错或者会正常,

依次缩小排查范围,找到问题的存在。

对于 errorMsg":"the number of 'fieldNames' and 'fieldValues' are not equal" 本身,指的就是您更新的字段值与该字段不匹配。
...