我在SAPUI5中使用textviews创建了一个简单的表单。 我必须将SOAP服务中的数据绑定到我的表单。 怎么做? 这是表单service.view.xml
@model CrowdFundMe.ViewModels.RewardViewModel
@{
ViewBag.Title = "Create";
}
<body>
@section Login{
@Html.Action("_Login", "User")
}
<h2>Create</h2>
<p>You are adding rewards for the project @ViewBag.ProjectTitle</p>
@using (Html.BeginForm("Create", "Reward", FormMethod.Post))
{
var u = ViewBag.AmountOfTiers;
for (int i = 0; i < u; i++)
{
var tier = i+1;
@Html.HiddenFor(model => model.ProjectId)
@Html.LabelFor(model => model.Tier, "Tier")<br />
@Html.TextBoxFor(model => model.Tier, new {@Value = tier, @readonly="readonly"})
<br />
<br />
@Html.LabelFor(model => model.Title, "Title")<br />
@Html.TextBoxFor(model => model.Title)
@Html.ValidationMessageFor(model => model.Title)
<br />
<br />
@Html.LabelFor(model => model.AmountOfItems, "Quantity available (leave blank if unlimited)")<br />
@Html.TextBoxFor(model => model.AmountOfItems)
@Html.ValidationMessageFor(model => model.AmountOfItems)
<br />
<br />
@Html.LabelFor(model => model.Description, "Description")<br />
@Html.EditorFor(model => model.Description)
@Html.ValidationMessageFor(model => model.Description)
<br />
<br />
}
<input type="submit" value="Create" />
}
如何处理模型创建并从SOAP服务中获取值? 由于我只熟悉OData服务,请帮助我绑定SOAP服务的值
答案 0 :(得分:2)
可以相当容易地完成(与Marc评论的相反,您只需要一个$.ajax
电话)和sap.ui.model.xml.XMLModel
:
// first create your SOAP request envelope
var soapRequest = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope/\" soap:encodingStyle=\"http://www.w3.org/2003/05/soap-encoding\">" +
" <soap:Body>" +
" <m:GetPrice xmlns:m=\"http://www.w3schools.com/prices\">" +
" <m:Item>Apples</m:Item>" +
" </m:GetPrice>" +
" </soap:Body>" +
"</soap:Envelope>";
// instantiate an XMLModel
var oModel = new sap.ui.model.xml.XMLModel();
$.ajax(sURL, { // sURL is the url you are sending the SOAP request to
method: "POST",
data: soapRequest,
dataType: "xml",
contentType: "text/xml; charset=\"utf-8\""
}).done(function(data, textStatus, jqXHR) {
// in the 'done' Promise, store the SOAP response into your XMLModel
oModel.setData(data);
}).fail(function(XMLHttpRequest, textStatus) {
jQuery.sap.log.fatal("The following problem occurred: " + textStatus, XMLHttpRequest.responseText + "," + XMLHttpRequest.status + "," + XMLHttpRequest.statusText);
});
有关详细信息,请参阅https://sapui5.hana.ondemand.com/#docs/api/symbols/sap.ui.model.xml.XMLModel.html