Skip to Content

How to pass dynamic data to sap.m.link sapui5

Hi All,

I have few doubts in using SAP.M.LINK.

Through my oData, I am passing multiple links/URLs to my front end. These links will be available under "Attachments" label.

I am getting the value of my 1st link as -

var Link1 = sItem.getBindingContext().getProperty("Link1");

and similary...

var Link2 = sItem.getBindingContext().getProperty("Link2"); and other links.

I tried using the below syntax, but it does not navigate to my URL(even when Link1 has correct value). When I hard coded, a URL in my HREF property, it got successfully navigated to that URL. I am not able to find an error in debug mode.

Please help me with what I am doing wrong.

Thanks

Meenakshi

capture.png (7.3 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Jul 04, 2017 at 11:10 AM

    Hi

    Please find below the view definition. I guess in your case the model which your binidng is more important. I created and XML view

    <mvc:View controllerName="mysap.ui5.demo.walk.controller.App" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:mvc="sap.ui.core.mvc"
    	xmlns="sap.m" xmlns:u="sap.ui.unified">
    	<App>
    		<pages>
    			<Page title="{i18n>title}">
    				<content>
    					<!--<u:Currency value="2300.12" currency="INR" useSymbol="true" />-->
    					<Text text="{ path: '/number', type: 'sap.ui.model.type.Currency', formatOptions: { showMeasure: false } }"/>
    					<!--<Text text="Hello World"/>-->
    					<Link id="Test" text="Link1" href="{path: '/link1'}"></Link>
    					<Link id="Test2" text="Link2" href="{path: '/link2'}"></Link>
    				</content>
    			</Page>
    		</pages>
    	</App>
    </mvc:View>
    

    The controller definition is as follows

    sap.ui.define([
    	"sap/ui/core/mvc/Controller", "sap/ui/model/json/JSONModel",
    	"sap/ui/core/format/NumberFormat"
    ], function(Controller, JSONModel, NumberFormat) {
    	"use strict";
    
    
    	return Controller.extend("mysap.ui5.demo.walk.controller.App", {
    		_data: {
    			"number": ["9999.99"],
    			"link1" : 'https://www.google.com',
    			"link2" : 'https://www.aol.com'
    		},
    
    
    		onInit: function(evt) {
    			var oModel = new JSONModel(this._data);
    			this.getView().setModel(oModel);
    			var oFmtSet =  NumberFormat.getCurrencyInstance();
    			// var oLocale = oFmtSet.getCurrencyInstance();
    		}
    	});
    
    
    });
    

    Thanks,

    Pavan

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jul 04, 2017 at 07:39 AM

    Hi Meenakshi,

    Can you try with 'Press' event in sap.m.Link..

    https://openui5.hana.ondemand.com/#docs/api/symbols/sap.m.Link.html#event:press

    I am not sure are you setting href value dynamically for the link.

    Regards,

    Mahi theja

    Add comment
    10|10000 characters needed characters exceeded