on 2024 May 22 7:54 PM
Hi
Why the alert is not displaying the text, I think my code is correct, but I don't know why its not displaying the text if i add {ProductID}
heres my code
Odata: Northwind from services.odata.org
Home.xml
<VBox id="_IDGenVBox3" class="sapUiSmallMargin">
<Title id="_IDGenTitle1" text="ProductID: {ProductID}" wrapping="true" />
<Label id="_IDGenLabel7" text="Name: {ProductName}" wrapping="true" class="sapUiTinyMarginBottom" />
<Label id="_IDGenLabel8" text="Available Stock: {UnitsInStock}" wrapping="true" class="sapUiTinyMarginBottom" />
<Text id="_IDGenText1" text="A great description with useful information about this project. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy." wrapping="true" />
</VBox>
<VBox id="_IDGenVBox4" class="sapUiSmallMargin">
<OverflowToolbar id="_IDGenOverflowToolbar1" design="Solid" class="sapContrast">
<!-- <ToolbarSpacer id="_IDGenToolbarSpacer2" /> -->
<Title id="_IDGenTitle2" text="Price: {UnitPrice}" wrapping="true" />
<Button id="_IDGenButton1" icon="sap-icon://cart-4" type="Transparent" press="onAddToCart()" />
<Button id="_IDGenButton2" icon="sap-icon://credit-card" type="Transparent" press="onBuy()" />
</OverflowToolbar>
</VBox>Home.controller.js
onAddToCart: function (){
var productID = this.getView().byId("_IDGenTitle1").getText();
alert(productID);
} Result
but if i remove the {ProductID} it is working fine
Request clarification before answering.
press="onAddToCart"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I did a quick try of this example. I am able to see the text correctly. May be can you check your binding, if the data is available.
sap.ui.define([
"sap/ui/core/mvc/Controller",
"sap/ui/model/json/JSONModel",
"sap/m/MessageBox"
],
/**
* @Param {typeof sap.ui.core.mvc.Controller} Controller
*/
function (Controller,JSONModel,MessageBox) {
"use strict";
return Controller.extend("com.demo.test1.controller.View1", {
onInit: function () {
let model = new JSONModel({
product: "Abc"
});
this.getView().setModel(model,"test")
},
handleAdd: function() {
let text = this.getView().byId("idProduct");
let textValue = text.getText();
MessageBox.success(textValue);
}
});
});<mvc:View controllerName="com.demo.test1.controller.View1"
xmlns:mvc="sap.ui.core.mvc" displayBlock="true"
xmlns="sap.m">
<Page id="page" title="{i18n>title}">
<content>
<Text id="idProduct" text="Product: {test>/product}" />
<Button id="idButton" text="Add" press="handleAdd" />
</content>
</Page>
</mvc:View>
| User | Count |
|---|---|
| 14 | |
| 8 | |
| 6 | |
| 6 | |
| 3 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.