Reputation: 65
I use dojo 1.9 in my aplication. When i pass the array (aID) to the xhr.post data, the array data will change and will convert in array, example:
aid = [3,4]
and xhr.post send aid =[[3],[4]]
why? I do not understand why this happens.
// 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);
}
});
});
Upvotes: 2
Views: 266
Reputation: 376
It is not a problem with xhr.post. In your code
dojo.forEach(items, function(selectedItem){
aID.push(grid.store.getValues(selectedItem,'id'));
});
you are using grid.store.getValues (note - plural) which returns an array. I think you need to be using grid.store.getValue or if you must use getValues to return multiple values, use grid.store.getValues(selectedItem,'id')[0]
Upvotes: 1