Skip to content

Instantly share code, notes, and snippets.

@ikiw
Created July 22, 2015 13:50
Show Gist options
  • Save ikiw/e43eee039164ad09433b to your computer and use it in GitHub Desktop.
Save ikiw/e43eee039164ad09433b to your computer and use it in GitHub Desktop.
ui5 connect to view function
<!DOCTYPE html>
<html><head>
<meta http-equiv='X-UA-Compatible' content='IE=edge' />
<meta http-equiv='Content-Type' content='text/html;charset=UTF-8'/>
<title>test</title>
<script id='sap-ui-bootstrap' type='text/javascript'
src='/sapui5/resources/sap-ui-core.js'
data-sap-ui-theme='sap_bluecrystal'
data-sap-ui-libs='sap.m'></script>
<!-- add 'sap.ui.table' and/or other libraries if required -->
<script id="view1" type="sapui5/xmlview">
<core:View xmlns:core="sap.ui.core" xmlns:m="sap.m"
controllerName="my.controller">
<m:List items="{/{{entitySet}}}">
<m:items>
<m:ObjectListItem title="{{{property}}}"/>
</m:items>
</m:List>
</core:View>
</script>
<script>
var config = {
entitySet: "Categories",
property: "CategoryName"
};
sap.ui.controller("my.controller", {
connectToView: function( view ) {
var attrs = document.evaluate( "//@*", view._xContent );
var attrlist = [];
var attr;
while( attr = attrs.iterateNext() ) attrlist.push( attr );
for (var i=0; i<attrlist.length; i++)
attrlist[i].value = attrlist[i].value.replace( /{{([^{}]*)}}/g, function( m, p1 ) {
return config[ p1 ];
} );
sap.ui.core.mvc.Controller.prototype.connectToView.apply( this, arguments );
},
onInit: function() {
this.getView().setModel( new sap.ui.model.odata.ODataModel(
"/uilib-sample/proxy/http/services.odata.org/V2/Northwind/Northwind.svc/",
{ json: true, loadMetadataAsync: true }
) );
}
});
sap.ui.xmlview({viewContent:jQuery('#view1').html()}).placeAt("content");
</script>
</head>
<body class='sapUiBody'>
<div id='content'></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment