2015-01-07 57 views
2

我實際上正在對來自AngularJS的轉換進行JSON-RPC調用。由於請求的內容類型爲application/json,輸入參數在上下文中自動提供,因此我不需要明確處理它。如何處理Moqui中的JSON響應?

這是我的請求「getUsers」這是在「教程」組件。

function($scope, $http) { 
    $http ({ 
     url: 'tutorial/getUsers', 
     method: "POST", 
     data: JSON.stringify({username:'demouser1'}), 
     headers: {'Content-Type': 'application/json'} 

    }).success(function(response){ 
     $scope.userList = response; 
    }); 
}]); 

,轉變的代碼編寫如下

<transition name="getUsers"> 
    <actions> 
     <service-call name="Tutorial.PartyServices.get#Users" in-map="context"/> 
    </actions> 
    <default-response type="none"/> 
</transition> 

服務看起來是這樣的

<service verb="get" noun="Users"> 
    <in-parameters> 
     <parameter name="username"/> 
    </in-parameters> 
    <actions> 
     <entity-find entity-name="PersonAndUserAccount" list="userList"> 
      <search-form-inputs default-order-by="firstName,lastName,username"/> 
      <econdition field-name="username" operator="equals" to-field-name="username"/> 
     </entity-find> 
     <script>ec.web.sendJsonResponse(userList)</script> 
    </actions> 
</service> 

我們發送JSON響應我的服務本身寫道ec.web.sendJsonResponse(userList)。這使服務與期望JSON作爲響應的服務調用緊密結合。如果我想在內部調用這個服務,即在Moqui中,我將不得不定義另一個服務。

所以我的問題是我可以處理這個響應在這個服務調用的過渡嗎?

回答

4

以下是可用於在轉換中提及JSON響應的示例。你可以參考ExampleApp.xml。

以下是供您參考的代碼片段。

<transition name="ExampleEntity" method="post"> 
    <service-call name="org.moqui.example.ExampleServices.createExample" in-map="ec.web.parameters" 
     web-send-json-response="true"/> 
<default-response type="none"/> 
</transition> 

HTH。

謝謝