[英]Reusing SAPUI5 control
I have an image and I need to use it at three places in a page. 我有一张图片,需要在页面的三个位置使用它。 I can create three image objects and use them separately at the required places. 我可以创建三个图像对象,并在所需的位置分别使用它们。 However, I need to know if there is any way to reuse the single image object at three places. 但是,我需要知道是否有任何方法可以在三个地方重用单个图像对象。 I tried to use prototype property of javascript but it is not working. 我尝试使用javascript的原型属性,但无法正常工作。 I initially tried this but only footer gets the image. 我最初尝试过此方法,但只有页脚才能获得图像。
var image = new sap.m.Image("id_image",{
src:"images/myImage.png"
});
return new sap.m.Page("id_page",{
enableScrolling:false,
customHeader:new sap.m.Bar("id_headerbar",{
contentRight:image
}),
content: [
],
footer:new sap.m.Bar("id_footerbar",{
contentLeft:image
}),
});
I tried to use the prototype property : 我试图使用prototype属性:
var image = new sap.m.Image();
image.prototype.src = "./images/myImage.png";
But it says: Cannot set property 'src' of undefined. 但是它说:无法设置未定义的属性“ src”。 Please help. 请帮忙。
you can use clone for that. 您可以使用克隆。 Following example may help you 以下示例可能对您有帮助
var itemDialog = new sap.ui.commons.Image({
src : "images/sort_asc.png",
tooltip : "Sort",
press : function() {
alert("hello");
}
});
and then use clone property whereever required.As for example for using it in Table column 然后在需要时使用克隆属性。例如,在“表”列中使用它
oTable.addColumn(new sap.ui.table.Column({
template : itemDialog.clone(),
width : "30px"
}));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.