2017-06-27 74 views
0

這裏我陣列格式如何通過Ajax POST請求的graphQl服務傳遞對象的數組

coordinates : [ { divId:"1234", divCor: { divleft:"1223", divtop: "455" }, imgCor: { imgleft:"78895", imgtop: "452"
} }, { divId:"1234", divCor :{ divleft:"1223", divtop: "455", }, imgCor :{ imgleft:"78895", imgtop: "452",
} }
]

我的Ajax請求是

`

var data = "mutation M{publishProduct(coordinates: "+this.state.coordinates+"){_id}}"; 

    console.log("publishProduct: "+JSON.stringify(data)); 

    $.ajax ({ 
     type: "POST", 
     url: "/", 
     contentType: "application/graphql", 
     data: data, 
     dataType : 'json', 
     success:(data) => { 

`

控制檯我保持在上面顯示爲

publishProduct: "mutation M{publishProduct(coordinates: [object Object],[object Object],[object Object]){ _id}} // Before passing data `

它不經過我所需要的格式。

請幫助我如何傳遞graphQl請求的對象數組。

回答

1

您必須在他們加入到突變字符串之前JSON.stringify座標:

var data = "mutation M{publishProduct(coordinates: "+JSON.stringify(this.state.coordinates)+"){_id}}"; 
+0

這看起來很簡單,我一定會做一個嘗試。謝謝。 – Goutham