So senden Sie ein json-Modell über REST-service mit sapui5
Ich bin mit SAPUI5 und ich habe ein XML-Formular, ich möchte die Daten senden, um meine REST-service mit Json-Modell.
Ich bin mit dem SAPUI5 MVC-Modell, um meine app.
Wie kann ich die Daten auf meinem server mit REST-und JSON?
sap.ui.controller("controller.NewTicket", {
onInit: function() {
this.router = sap.ui.core.UIComponent.getRouterFor(this);
this.router.attachRoutePatternMatched(this._handleRouteMatched, this);
},
_handleRouteMatched:function(evt){
if("NewTicket" !== evt.getParameter("name")){
return;
}
var id = evt.getParameter("arguments").id;
var model = new sap.ui.model.json.JSONModel({id:id});
this.getView().setModel(model,"data");
},
enviar:function() {
jQuery.sap.require("sap.m.MessageBox");
//open a fully configured message box
sap.m.MessageBox.show("Confirmar a abertura do chamado?",
sap.m.MessageBox.Icon.QUESTION,
"Confirmar",
[sap.m.MessageBox.Action.YES, sap.m.MessageBox.Action.NO],
function(sResult) {
if(sResult == sap.m.MessageBox.Action.YES)
{
var oModel = new sap.ui.model.json.JSONModel();
var aData = jQuery.ajax({
type : "POST",
contentType : "application/json",
url : "http://192.168.0.32:9082/maxrest/rest/mbo/sr/?description="+ **deviceModel.sr.description** +"&_format=json&_compact=true&_verbose=true",
dataType : "json",
async: false,
success : function(data,textStatus, jqXHR) {
oModel.setData({modelData : data});
sap.m.MessageBox.show("ABRIU");
},
error : function(data,textStatus, jqXHR) {
oModel.setData({modelData : data});
sap.m.MessageBox.show(textStatus);
}
})}
else
{
}
},
sap.m.MessageBox.Action.YES);
var deviceModel = new sap.ui.model.json.JSONModel({
sr : [{
description: "",
long_description: ""
}]});
deviceModel.setDefaultBindingMode("TwoWay");
sap.ui.getCore().setModel(deviceModel);
jQuery.sap.require("sap.m.MessageToast");
sap.m.MessageToast.show(deviceModel.getData().sr.description);
}
});
... Und der Blick...
<mvc:View xmlns:mvc="sap.ui.core.mvc" displayBlock="true" xmlns="sap.m" xmlns:co="sap.ui.commons"
xmlns:f="sap.ui.layout.form" xmlns:core="sap.ui.core" controllerName="com.maximo.controller.NewTicket">
<Page id="NewTicket" enableScrolling="true" title="{i18n>newTicket}" >
<content>
<f:SimpleForm >
<core:Title level="H5"
text="O chamado será aberto em seu nome e você será o usuário afetado"/>
<Label text="Resumo"/>
<Input type="Text" maxLength="100" value="{/sr/description}"/>
<Label text="Detalhes"/>
<TextArea height="50%" cols="800" value="{/sr/long_description}"/>
</f:SimpleForm>
</content>
<customHeader>
<Bar>
<contentLeft>
<Button icon="sap-icon://nav-back" press="voltarMenu"/>
</contentLeft>
<contentMiddle>
<Label text="{i18n>newTicket}"/>
</contentMiddle>
</Bar>
</customHeader>
<footer>
<Bar>
<contentMiddle>
<Button id="btnSend" text="{i18n>send}" press="enviar" icon="sap-icon://add-activity-2"/>
</contentMiddle>
</Bar>
</footer>
</Page>
- Hi @mayconbelfort, haben Sie versucht, mit Hilfe von JSON-Modell loadData - Funktion , mit der Art wie 'POST -'
Du musst angemeldet sein, um einen Kommentar abzugeben.
Aus meiner Erfahrung habe ich herausgefunden, dass es einfacher ist, verwenden Sie OData-Modell der "JSON" - Typ.
Es ist, wie ich alle meine Anforderungen, die manuelle oder automatisierte (manuelle Ereignis-oder event-Seite).
Für eine "post" - Veranstaltung, die ich verwendet eine token-fech:
Und nach, dass ich die eigentliche "POST" mit der "Create" - Methode:
var user = applicationContext.registrationContext.user;
var password = applicationContext.registrationContext.password;