Dojo 解析器分配值数组而不是值

Dojo Parser assigning arrays of values rather than value

我试图使用以下代码遍历 dojo 数据网格的选定值并获取选定的行并将其发送到 Spring MVC,以便我可以映射到对象列表,但是dojo 正在发送数组对象中的所有值,somebpdy 可以让我知道我是否做错了什么

Getting the selected values from the grid:

 function getUpdatedRowsFromDataGrid(){
     var items = grid.selection.getSelected();   
     window.arr = [];  
        if(items.length) {
                 // Iterate through the list of selected items.
            // The current item is available in the variable
            // "selectedItem" within the following function:
            var spocUpdatedValues = [];
            dojo.forEach(items, function(selectedItem){
                if(selectedItem !== null){
                    // Iterate through the list of attributes of each item.
                    // The current attribute is available in the variable
                    // "attribute" within the following function:
                      var obj = new Object();
                    dojo.forEach(grid.store.getAttributes(selectedItem), function(attribute){
                        // Get the value of the current attribute:
                        var value = grid.store.getValues(selectedItem, attribute);                      
                        // Now, you can do something with this attribute/value pair.
                        // Our short example shows the attribute together
                        // with the value in an alert box, but we are sure, that
                        // you'll find a more ambitious usage in your own code:
                        switch (attribute)
                        {
                           case "spocId":
                                 obj.spocId= value;
                                  break;  
                           case "spocEmployeeFirstName":
                                 obj.spocEmployeeFirstNameValue = value;
                                   break;
                           case "spocEmployeeLastName":
                                 obj.spocEmployeeLastNameValue = value;
                                  break;                   
                            case "spocPhoneNmbr":
                                obj.spocPhoneNmbrValue = value;
                                  break;
                            case "spocStatusCD":
                                 obj.spocStatusCDValue = value;
                                  break;
                            case "spocLocationCD":
                                obj.spocLocationCDValue = value;
                                  break;
                            default: 
                               break;
                        }

                        //obj = {"spocId":spocValue,"spocEmployeeFirstName":spocEmployeeFirstNameValue,"spocEmployeeLastName":spocEmployeeLastNameValue,"spocPhoneNmbr":spocPhoneNmbrValue,"spocStatusCD":spocStatusCDValue,"spocLocationCD":spocLocationCDValue}
//                         alert('attribute: ' + attribute + ', value: ' + value);

                    });  
                     spocUpdatedValues.push({"spocId": obj.spocId,"spocEmployeeFirstNameValue": obj.spocEmployeeFirstNameValue,"spocEmployeeLastNameValue":obj.spocEmployeeLastNameValue,"spocPhoneNmbrValue": obj.spocPhoneNmbrValue,"spocStatusCDValue":  obj.spocStatusCDValue,"spocLocationCDValue": obj.spocLocationCDValue}) 

                } // end if
            })
        }  
    return spocUpdatedValues;
 }  

Sending it to UI

function sendText(){
        my_form=document.createElement('FORM');
        my_form.name='myForm';
        my_form.method='POST';
        my_form.action='/mmworkloadmanager/wlm/updatespoc.html';

        my_tb=document.createElement('INPUT');
        my_tb.type='HIDDEN';
        my_tb.name='spocUpdatedValues';
        my_tb.value=dojo.toJson(getUpdatedRowsFromDataGrid());

        my_form.appendChild(my_tb);

        document.body.appendChild(my_form);

        my_form.submit();
}
o/p 

[{"spocId":[60],"spocEmployeeFirstNameValue":["Joy                      "],"spocEmployeeLastNameValue":["M                                  "],"spocPhoneNmbrValue":["9727664994"],"spocStatusCDValue":["A"],"spocLocationCDValue":["50  "]},{"spocId":[61],"spocEmployeeFirstNameValue":["PJ                       "],"spocEmployeeLastNameValue":["J                                  "],"spocPhoneNmbrValue":["9729969171"],"spocStatusCDValue":["C"],"spocLocationCDValue":["56  "]}]

sending every value as an array , can some body suggest whether i need to modify any part of code to avoid the array.

我认为这里的问题是您在 value 变量中放置了一个数组。

因为 grid.store.getValues(selectedItem, attribute) 将 return 一个值,但是作为一个数组,所以你必须将这个值解析为一个字符串,尝试以下操作:

var value = grid.store.getValues(selectedItem, attribute)[0];

或:

像这样使用JavaScript Array join() Method

 var value = grid.store.getValues(selectedItem, attribute).join();

我认为应该这样做。