Passing in multiple data at once take EasyUI Datagrid as an example

Keywords: JSON Attribute

There are many ways. I just didn't think of it before. I came across it when I was doing the project and wrote it down by the way

For example, I want to transfer the following data to the background:

Popularize the following other knowledge:

In JS, [] means array , {} represents the object; generally used in JSON;
For example: var json={"eles":["aaa","bbb","ccc","ddd"]};
The value of eles attribute of json is an array of four elements;
You can get these values through json.eles[0], json.eles[1]...
In addition, var arr = new Array(); in js, it can be equivalent to var arr = [];

Method: first define an array var Items = [];

Foreground code

 $.messager.confirm('Confirm operation', 'Please confirm to submit!', function(r){
            if (r){
                var rows = DGAManager.$_Tab_OrderB.datagrid("getRows"); //Get all rows of the current EasyUI page and return array
                for(i=0;i<rows.length;i++){  //Traversing array
                    var item = new Object();  //new an Object class gives item item.rawid equivalent to item.setRawID (rows[i].id)
                    item.rawId = rows[i].id;
                    item.rawName = rows[i].name;
                    item.rawAmount = rows[i].amount;
                    item.rawPrice = rows[i].price;
                    item.birthTime = rows[i].birthTime;
                    item.deadTime = rows[i].deadTime;
                    item.shelfTime = rows[i].shelfTime;
                    items.push(item);
                }
                var data={
                    "rawTotal":document.getElementById("rawTotal").innerText,
                    "items" : items
                }
                $.ajax({
                    type : 'post',
                    contentType : "application/json;charset=utf-8",
                    data : JSON.stringify(data),    //Convert to JSON data
                    url : urlA+"/data/ZBOrder/addZBOrder",
                    success : function(rsdata){ //Callback function
                        items=[];
                        var rows = DGAManager.$_Tab_OrderB.datagrid("getRows");
                        var copyRows = [];
                        for ( var j= 0; j < rows.length; j++) {
                            copyRows.push(rows[j]);
                        }

 

Background code:

 @RequestMapping("addZBOrder")
    @ResponseBody    //Add store order
    public HRResult addZBOrder(@RequestBody ZBOrderEntity zborderEntity){
        StoreVO storeVO = (StoreVO) SecurityUtils.getSubject().getSession().getAttribute("store");
        ZBOrderQuery zborderquery = new ZBOrderQuery();
        zborderquery.setStoreId(storeVO.getId());
        zborderquery.setStoreName(storeVO.getName());

        return zbOrderService.addZBOrder(zborderquery,zborderEntity);
    }
public class ZBOrderEntity {

    private float rawTotal;
    private List<ZBOrderContentQuery> items;

    public ZBOrderEntity() {
    }

    public ZBOrderEntity(float rawTotal, List<ZBOrderContentQuery> items) {
        this.rawTotal = rawTotal;
        this.items = items;
    }

    public float getRawTotal() {
        return rawTotal;
    }

    public void setRawTotal(float rawTotal) {
        this.rawTotal = rawTotal;
    }

    public List<ZBOrderContentQuery> getItems() {
        return items;
    }

    public void setItems(List<ZBOrderContentQuery> items) {
        this.items = items;
    }
}

 

Posted by khurramijaz on Sun, 05 Jan 2020 15:04:44 -0800