有没有办法在SAPUI5中覆盖标准控件的方法?我想覆盖CalendarRow.js的方法' _getAppointmentsSorted'
我尝试复制粘贴整个文件并更改方法,但后来我收到以下错误:
无法加载 '是/ amistaAdminPlanning /控制/ MyCalendarRowRenderer.js'从 ./controls/MyCalendarRowRenderer.js:404 - 未找到
我尝试通过像这样指定渲染器来修复此错误:
3
找到了CalendarRowRenderer,但渲染方法并没有像它应该的那样执行,并且会弹出以下错误消息:
无法读取属性' getId' CalendarRowRenderer.js中的未定义 ?eval:6
任何人都知道它为什么会这样?
renderer: function(oRm, oControl) {
sap.ui.unified.CalendarRowRenderer.render(oRm, oControl);
}
答案 0 :(得分:0)
而不是"复制粘贴整个文件"您应该创建自己的自定义控件,例如CalendarRowExtended,并覆盖自定义控件中的函数。
这些链接可能很有用:
Extending Buttons with Additional Events
编辑:抱歉,没有看到Christoph的评论,因为它是在我前面几分钟写的。但我想这个想法是一样的。
答案 1 :(得分:0)
我没有详细测试它,但我认为以下应该有效:
创建文件 app_name_space /control/CalendarRowCustom.js 文件夹“控件”与“控制器”,“视图”文件夹位于同一级别。
使用以下内容填充CalendarRowCustom.js:
sap.ui.define(
['sap/ui/unified/CalendarRow'],
function(CalendarRow) {
"use strict";
return CalendarRow.extend("app_name_space.control.CalendarRowCustom",{
_getAppointmentsSorted: function() {
// Here goes your custom code
},
renderer: {}
});
}
);
根据文档中的this example,renderer: {}
应该继承父控件的功能。
然后你应该可以在这样的视图中使用你的自定义控件:
<mvc:View controllerName="..." xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:mvc="sap.ui.core.mvc" xmlns:cust="app_name_space.control">
<cust:CalendarRowCustom />
</mvc:View>
使用您在视图和控件中定义的命名空间替换“ app_name_space ”。