Sapui5 单击第二个选项卡并返回时删除按钮
我用下面的代码来显示简单的按钮,当你点击Tab2并返回到旧的选项卡时,按钮被删除了,你知道如何把它永久地放在tab1中吗 这是控制器外壳Sapui5 单击第二个选项卡并返回时删除按钮,sapui5,Sapui5,我用下面的代码来显示简单的按钮,当你点击Tab2并返回到旧的选项卡时,按钮被删除了,你知道如何把它永久地放在tab1中吗 这是控制器外壳 onInit: function() { this.oViewBuffer ={}; this.oViewBuffer.btn = sap.ui.jsview("codetalk.Main"); var oShell = sap.ui.getCore().byId("main-shell"); oShell.se
onInit: function() {
this.oViewBuffer ={};
this.oViewBuffer.btn = sap.ui.jsview("codetalk.Main");
var oShell = sap.ui.getCore().byId("main-shell");
oShell.setContent(this.oViewBuffer.btn);
},
onWorksetItemSelected:function(oEvent){
var oShell = sap.ui.getCore().byId("main-shell");
var key = oEvent.getParameter("key");
oShell.setContent(this.oViewBuffer[key]);
}
这是JS视图
createContent : function(oController) {
var oButton = new sap.ui.commons.Button({
text:"Hello Test",
tooltip:"This is toolTip",
press:function(){
alert("test alert");
}
});
return oButton;
}
这是外壳的视图
createContent : function(oController) {
var oButton = new sap.ui.ux3.NavigationItem({
key:"bth",
text:"Tab 1"
});
var oMusicStore = new sap.ui.ux3.NavigationItem({
key:"btn2",
text:"Tab 2"
});
var oShell = new sap.ui.ux3.Shell({
id:"main-shell",
appTitle:"Demo",
worksetItems:[oButton,oMusicStore],
worksetItemSelected:[oController.onWorksetItemSelected,oController]
});
return oShell;
}
在shell
view.js中删除最后一行
范例
首先,我建议删除shell id()中的“-”,并改用camel case
其次,您可以使用Init函数中的按钮调用视图,但一旦调用完毕,您就可以使用控制器处理工作项,并根据密钥设置工作项。到现在为止,一直都还不错。
但是您的WorksetItem与任何内容都没有关联,因此当您单击第一个选项卡时,shell没有理由向您显示该按钮
我建议使用id初始化视图,并根据该id将内容存储在shell控制器中
例如:
var oViewButton = sap.ui.view("bth",{
viewName : "codetalk.Main",
type : sap.ui.core.mvc.ViewType.JS
)} //do that in your view where you define your Shell
//do the same for your view with the musicstore also in the view with the Shell
//your id of the view must match the key of your worksetItem
在shell的控制器中执行以下操作:
onWorksetItemSelected : function(oEvent){
var oShell = sap.ui.getCore().byId("mainShell");
var key = oEvent.getParameter("key");
var oView = sap.ui.getCore().byId(key);
oShell.setContent(oView);
}
此解决方案将绕过Shell的内容聚合,但至少它对我有效
onWorksetItemSelected : function(oEvent){
var oShell = sap.ui.getCore().byId("mainShell");
var key = oEvent.getParameter("key");
var oView = sap.ui.getCore().byId(key);
oShell.setContent(oView);
}