Javascript 隐藏Fiori母版详细信息页面中的批准/拒绝按钮
我希望根据某些过滤条件隐藏Fiori应用程序详细信息页面中的“批准/拒绝”按钮。过滤器通过视图/控制器扩展添加到主列表视图(左侧视图)中。 现在,如果用户选择某种类型的过滤器(比如说,过去的订单),那么“订单详细信息”页面中不应显示“批准/拒绝”按钮。 这就是我在Header/Details视图中定义按钮的方式Javascript 隐藏Fiori母版详细信息页面中的批准/拒绝按钮,javascript,sapui5,sap-fiori,Javascript,Sapui5,Sap Fiori,我希望根据某些过滤条件隐藏Fiori应用程序详细信息页面中的“批准/拒绝”按钮。过滤器通过视图/控制器扩展添加到主列表视图(左侧视图)中。 现在,如果用户选择某种类型的过滤器(比如说,过去的订单),那么“订单详细信息”页面中不应显示“批准/拒绝”按钮。 这就是我在Header/Details视图中定义按钮的方式 this.oHeaderFooterOptions = { oPositiveAction: {
this.oHeaderFooterOptions = {
oPositiveAction: {
sI18nBtnTxt: that.resourceBundle.getText("XBUT_APPROVE"),
id :"btn_approve",
onBtnPressed: jQuery.proxy(that.handleApprove, that)
},
oNegativeAction: {
sI18nBtnTxt: that.resourceBundle.getText("XBUT_REJECT"),
id :"btn_reject",
onBtnPressed: jQuery.proxy(that.handleReject, that)
},
但是,在运行时,这些按钮没有分配我提到的ID,而是使用_button0和_button1的ID创建的
有没有办法在主列表视图中隐藏这些按钮
谢谢。您可以在控制器上多次调用setHeaderFooterOptions,例如:
//Code inside of the controller
_myHeaderFooterOptions = {
oPositiveAction: {
sI18nBtnTxt: that.resourceBundle.getText("XBUT_APPROVE"),
id :"btn_approve",
onBtnPressed: jQuery.proxy(that.handleApprove, that)
},
oNegativeAction: {
sI18nBtnTxt: that.resourceBundle.getText("XBUT_REJECT"),
id :"btn_reject",
onBtnPressed: jQuery.proxy(that.handleReject, that)
}
},
//set the initial options
onInit: function () {
this.setHeaderFooterOptions(this._myHeaderFooterOptions);
},
//modify the options in an event
onFilter : function () {
//remove the negative action to hide it
this._myHeaderFooterOptions.oNegativeAction = undefined;
this.setHeaderFooterOptions(this._myHeaderFooterOptions);
},
//further code
因此,通过操纵“MyHeaderFooter”选项,您可以影响显示的按钮。首先,在定义HeaderFooter选项时,您应该使用
sId
而不是id
,您可以通过sId
获得页脚按钮,例如,Approve按钮
this._oControlStore.oButtonListHelper.mButtons["btn_approve"]
请检查以下代码段:
S2.view.controller:您有一个定义如下的筛选器事件处理程序,用于将事件OrderTypeChanged
发布到S3.view.controller
onFilterChanged: function(oEvent) {
// Set the filter value, here i use hard code
var sFilter = "Past Orders";
sap.ui.getCore().getEventBus().publish("app", "OrderTypeChanged", {
filter: sFilter
});
}
onInit: function() {
///
var bus = sap.ui.getCore().getEventBus();
bus.subscribe("app", "OrderTypeChanged", this.handleOrderTypeChanged, this);
},
getHeaderFooterOptions: function() {
var oOptions = {
oPositiveAction: {
sI18nBtnTxt: that.resourceBundle.getText("XBUT_APPROVE"),
sId: "btn_approve",
onBtnPressed: jQuery.proxy(that.handleApprove, that)
},
oNegativeAction: {
sI18nBtnTxt: that.resourceBundle.getText("XBUT_REJECT"),
sId: "btn_reject",
onBtnPressed: jQuery.proxy(that.handleReject, that)
}
};
return oOptions;
},
handleOrderTypeChanged: function(channelId, eventId, data) {
if (data && data.filter) {
var sFilter = data.filter;
if (sFilter == "Past Orders") {
this._oControlStore.oButtonListHelper.mButtons["btn_approve"].setVisible(false);
}
//set Approve/Reject button visible/invisible based on other values
//else if(sFilter == "Other Filter")
}
}
S3.view.controller:订阅事件OrderTypeChanged
自S2.view.controller
onFilterChanged: function(oEvent) {
// Set the filter value, here i use hard code
var sFilter = "Past Orders";
sap.ui.getCore().getEventBus().publish("app", "OrderTypeChanged", {
filter: sFilter
});
}
onInit: function() {
///
var bus = sap.ui.getCore().getEventBus();
bus.subscribe("app", "OrderTypeChanged", this.handleOrderTypeChanged, this);
},
getHeaderFooterOptions: function() {
var oOptions = {
oPositiveAction: {
sI18nBtnTxt: that.resourceBundle.getText("XBUT_APPROVE"),
sId: "btn_approve",
onBtnPressed: jQuery.proxy(that.handleApprove, that)
},
oNegativeAction: {
sI18nBtnTxt: that.resourceBundle.getText("XBUT_REJECT"),
sId: "btn_reject",
onBtnPressed: jQuery.proxy(that.handleReject, that)
}
};
return oOptions;
},
handleOrderTypeChanged: function(channelId, eventId, data) {
if (data && data.filter) {
var sFilter = data.filter;
if (sFilter == "Past Orders") {
this._oControlStore.oButtonListHelper.mButtons["btn_approve"].setVisible(false);
}
//set Approve/Reject button visible/invisible based on other values
//else if(sFilter == "Other Filter")
}
}
推荐: SAP Fiori设计原则仅讨论禁用页脚按钮,而不是更改
按钮的可见性。
根据筛选条件,可以如下方式禁用:
this.setBtnEnabled("btn_approve", false);
要再次启用:this.setbtnabled(“btn_approve”,true)代码>
同样,您可以使用this.setBtnText(“btn_approve”,“buttonText”)更改按钮文本代码>
其他方式:如前所述使用
你好,托比亚斯-谢谢你的回复。问题是过滤器事件处理程序在不同的控制器(S2列表)中定义,按钮在S3头视图中。在这种情况下,如何控制按钮的可见性?您好,您可以通过组件的事件总线触发事件,请参见。您在S3控制器中发布事件,并在S2控制器中订阅。你可以修改HeaderFooterOptionShiTobias,这是个好主意。谢谢你的回复。对不起,回来晚了。除了获取全局事件总线,还有什么方法可以获取组件的事件总线吗?我认为这是合适的。您好,在我发布的链接中有一个函数描述为myComponent.getEventBus()。此事件总线将发送仅对此事件总线实例可见的事件Hi Allen,感谢您的回复。对不起,回来晚了。不是获取全局事件总线,而是有方法获取组件的事件总线吗?好的,所以我得到了组件的事件总线..var c=sap.ui.core.component.getowneridf(this.getView());var localEventBus=sap.ui.component(c.getEventBus();publish(“zPrApp”、“showHideApprovalButtons”{id:sButtonId});然后在另一个视图controllerlocalEventBus.subscribe(“zPrApp”、“showHideApprovalButtons”、this.handleApprovalButtonsVisibility、this);这在台式机上运行良好,但在iPhone上失败。奇怪。手机上的错误是拒绝按钮未定义。此。_oControlStore.oButtonListHelper.mButtons仅返回批准按钮。.任何建议。.您好,我在Chrome iPhone emulator下尝试过,它正在为拒绝按钮工作。奇怪。艾伦,我在真实的iPhone和Chrome模拟器中试过,拒绝按钮不起作用。您是否将“拒绝”按钮视为操作表,还是将其显示在“批准”旁边。在我的情况下,拒绝按钮是作为操作表出现的。您好,请尝试获取此按钮。_oControlStore.oButtonListHelper.oOverflowList.mButtons以查看拒绝按钮是否在其中?如果在,则有一个指示器。_oControlStore.oButtonListHelper.bHasOverflow。