如何在UI5中将MockServer用于模拟REST调用?如果我使用以下实现,仍然会使用现实生活中的数据:
App.controller.js
...
var oMyRequest = [{
method: "GET",
path: new RegExp("posts?(.*)"),
response: function (oXhr, sUrlParams) {
jQuery.sap.log.debug("Incoming request for ShowAddButton");
oXhr.respondJSON(200, {}, JSON.stringify({
d: {
test: true
}
}));
}}];
var oMockServer = new MockServer({
rootUri: "/posts"
})
oMockServer.setRequests(oMyRequest)
oMockServer.start()
$.ajax({
method: "GET",
url: "https://blog.mydomain.de/posts?",
dataType: "JSON"
}).done(function (data) { console.log(data) });