Javascript dojo xhr.post,我在xhr.post数据中放置了一个数组,但是数据被更改了,为什么?

Javascript dojo xhr.post,我在xhr.post数据中放置了一个数组,但是数据被更改了,为什么?,javascript,arrays,dojo,Javascript,Arrays,Dojo,我在应用程序中使用Dojo1.9。 当我将数组(aID)传递给xhr.post数据时,数组数据将发生更改并在数组中转换,例如: 援助=[3,4] 和xhr.post发送帮助=[[3],[4]] 为什么??我不明白为什么会这样 // Create the grid grid = new EnhancedGrid({ id: 'grid', store: Mystore, structure: layout, //selectionM

我在应用程序中使用Dojo1.9。 当我将数组(aID)传递给xhr.post数据时,数组数据将发生更改并在数组中转换,例如:

援助=[3,4]

和xhr.post发送帮助=[[3],[4]]

为什么??我不明白为什么会这样

 // Create the grid
grid = new EnhancedGrid({
        id: 'grid',
        store: Mystore,
        structure: layout,
        //selectionMode: multiple,
        //keepSelection: true,
        escapeHTMLInData: false,
        width: '100%',
        autoHeight: true,
        rowSelector: gridLayout,
        noDataMessage: '<span class=\"dojoxGridNoData\">No Devices</span>',
        plugins: {
        pagination: {
        pageSizes: [],
        description: true,
        sizeSwitch: true,
        pageStepper: true,
        gotoButton: true,
        /*page step to be displayed*/
        maxPageStep: 4,
        /*position of the pagination bar*/
        position: "bottom"
        },
        indirectSelection: {headerSelector:true, width:gridLayout, styles:"text-align: center;"}
        }
        })
        grid.placeAt('gridContainer');
        grid.startup();

var button4 = new Button({ label:"Delete device"});
            //button4.startup();
            button4.placeAt("buttonD");
            button4.on("click", function(event) {
            var aID =[];
            var items = grid.selection.getSelected();
            dojo.forEach(items, function(selectedItem){                      
aID.push(grid.store.getValues(selectedItem,'id'));                                                             
                        });

            console.info(aID);
            xhr.post("/****/***/***/***/action",{
                            sync: true,
                            data: dojo.toJson({
                            action: 255,
                            targets: aID
                            }),
                            headers: { 'Content-Type': 'application/json','x-ds-session': cookie("token")},
                            handleAs: "json"
                            }).then(function(data1){


                            },function(err){
                                    if( (err.response.text).indexOf("Invalid session token") != -1 ){
                                                                    window.location.reload(true);
                            }
                            });
                        });
//创建网格
网格=新增强网格({
id:'网格',
商店:Mystore,
结构:布局,
//选择模式:多个,
//基普选举:没错,
escapeHTMLInData:false,
宽度:“100%”,
自动高度:正确,
行选择器:gridLayout,
nodata消息:“无设备”,
插件:{
分页:{
页面大小:[],
描述:对,
开关:是的,
是的,
戈托布顿:没错,
/*要显示的页面步骤*/
maxPageStep:4,
/*分页条的位置*/
位置:“底部”
},
间接选择:{headerSelector:true,width:gridLayout,styles:“文本对齐:居中;”}
}
})
grid.placeAt('gridContainer');
grid.startup();
var button4=新按钮({标签:“删除设备”});
//按钮4.启动();
按钮4.放置位置(“按钮”);
按钮4.打开(“单击”,功能(事件){
var aID=[];
var items=grid.selection.getSelected();
forEach(项,函数(selectedItem){
推送(grid.store.getValues(selectedItem,'id');
});
控制台信息(aID);
xhr.post(“/***/***/***/***/action”{
是的,
数据:dojo.toJson({
行动:255,
目标:援助
}),
标题:{'Content-Type':'application/json','x-ds-session':cookie(“令牌”)},
handleAs:“json”
}).then(函数(数据1){
},函数(err){
if((err.response.text).indexOf(“无效会话令牌”)!=-1){
window.location.reload(true);
}
});
});

xhr.post没有问题。在代码中

dojo.forEach(items, function(selectedItem){                      
        aID.push(grid.store.getValues(selectedItem,'id'));                                                             
    });
您正在使用grid.store.getValues(注意-复数),它返回一个数组。我认为您需要使用grid.store.getValue或者如果必须使用getValues返回多个值,请使用
grid.store.getValues(selectedItem,'id')[0]

您还可以使用类似于
aID.push.apply(aID,grid.store.getValues(selectedItem,'id'))的东西
如果要将存储中的所有值添加到正在发布的数组中,请执行
POST
。看见