2017-09-13 59 views
2
var updFileId = "12345"; 

$scope.compGridJson = { 
    "peers": ["localhost:7051", "localhost:8051"], 
    "fcn": "move", 
    "args": ["compGridDetails", "{" + 
    "\"FromParty\":\"Valuelabs\",\"CreatedState\":\"24/08/2017\",\"FileUId\":\"+updFileId+\",\"Status\":\"ValueLabs Change Request\"}" 
    ] 
} 
$http({ 
    method: "POST", 
    url: "http://localhost:4000/channels/mychannel/chaincodes/changedneww727", 
    data: $scope.compGridJson, 
    headers: { 
    'Authorization': 'Bearer token', 
    'Content-Type': 'application/json' 
    } 
}).success(function(data, status, headers, config) { 

}).error(function(data, status, headers, config) { 

}); 

以上是我的代碼。在「FileUId」的Json數據中,我正在動態地傳遞數據。但它不是動態獲取數據。我爲這個價值改變了很多方法,但並沒有動態地進行。我想動態地傳遞這個「12345」的值。可以幫助我。無法在json數據中動態傳遞數據

+0

有什麼,而不是'12345'? – lumio

+0

你不是以'+ updFileId +'爲結尾的字符串。它應該看起來像'... \「FileUId \」:\「」+ a +「\」...' –

+0

@Björn它的工作謝謝你 –

回答

2

字符串連接不正確。你應該嘗試:

$scope.compGridJson = { 
    "peers": ["localhost:7051", "localhost:8051"], 
    "fcn": "move", 
    "args": ["compGridDetails", "{" + 
    "\"FromParty\":\"Valuelabs\",\"CreatedState\":\"24/08/2017\",\"FileUId\":\""+updFileId+"\",\"Status\":\"ValueLabs Change Request\"}" 
    ] 
} 
0

您應該使用json.stringify()

$scope.compGridJson = { 
     "peers": ["localhost:7051", "localhost:8051"], 
     "fcn": "move", 
     "args": ["compGridDetails", JSON.stringify({ 
             FromParty : "Valuelabs", 
             CreatedState: "24/08/2017", 
             FileUId : updFileId, 
             Status : "ValueLabs Change Request" 
     })] 
     }