<html>
<head>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<meta charset="utf-8">
<title>MVC with XmlView</title>
<!-- Load UI5, select "blue crystal" theme and the "sap.m" control library -->
<script id='sap-ui-bootstrap'
src='https://sapui5.hana.ondemand.com/resources/sap-ui-core.js'
data-sap-ui-theme='sap_bluecrystal'
data-sap-ui-libs='sap.m'
data-sap-ui-xx-bindingSyntax='complex'></script>
<!-- DEFINE RE-USE COMPONENTS - NORMALLY DONE IN SEPARATE FILES -->
<!-- define a new (simple) View type as an XmlView
- using data binding for the Button text
- binding a controller method to the Button's "press" event
- also mixing in some plain HTML
note: typically this would be a standalone file -->
<script id="view1" type="sapui5/xmlview">
<mvc:View xmlns="sap.m" xmlns:mvc="sap.ui.core.mvc" controllerName="my.own.controller">
<Page>
<Table items="{/Orders}" updateFinished="onTableUpdateFinished">
<columns>
<Column >
<Text text="My Value From OData"/>
</Column>
<Column>
<Text text="My Value From AJAX"/>
</Column>
</columns>
<items>
<ColumnListItem>
<cells>
<ObjectIdentifier title="{CustomerID}"/>
<ObjectIdentifier text="{parts:[{path:'CustomerID'}, {path:'myOtherModel>/'}], formatter: '.myFormatter'}"/>
</cells>
</ColumnListItem>
</items>
</Table>
</Page>
</mvc:View>
</script>
<script>
// define a new (simple) Controller type
sap.ui.controller("my.own.controller", {
onInit: function(){
var myOtherModel = new sap.ui.model.json.JSONModel();
this.getView().setModel(myOtherModel, "myOtherModel");
//Here your AJAX call to get the data from a POST request
/*
$.ajax({
type: "POST",
url: url,
data: data,
success: this.ajaxSuccess,
dataType: dataType
});
*/
//Let's simulate that there was a success receiving the following data
var data = {
VINET: {
message: "VINET Rocks!!"
},
WARTH: {
message: "WARTH is good company!!"
},
RICSU: {
message: "RICSU I don't like"
},
HANAR: {
message: "HANAR was my first customer"
}
}
this.ajaxSuccess(data);
},
ajaxSuccess: function(data){
this.getView().getModel("myOtherModel").setData(data)
},
myFormatter: function(sCustomerID, otherModelData){
// This formatter will be executed for each table row.
// In the first parameter, the value binded in the first column
// In the second parameter, the node you want of your second model (in this case the root node)
//do whatever you want here and return a string for the 'text' property in this case
if(otherModelData[sCustomerID]){
// If there is a node in your second model with a node for the given Customer ID, then return the message into it
return otherModelData[sCustomerID].message;
}
//Otherwise return empty string
return "";
}
});
/*** THIS IS THE "APPLICATION" CODE ***/
// create a Model and assign it to the View
// Using here the HEROKU Proxy to avoid a CORS issue
var uri = "https://cors-anywhere.herokuapp.com/services.odata.org/Northwind/Northwind.svc"; // local proxy for cross-domain access
var oNorthwindModel = new sap.ui.model.odata.ODataModel(uri, {
maxDataServiceVersion: "2.0"
});
// instantiate the View
var myView = sap.ui.xmlview({viewContent:jQuery('#view1').html()}); // accessing the HTML inside the script tag above
// Set the OData Model
myView.setModel(oNorthwindModel);
myView.placeAt('content');
</script>
</head>
<body id='content' class='sapUiBody'>
</body>
</html>
Output
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |