首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SRM UI插件增强功能

SRM UI插件增强功能
EN

Stack Overflow用户
提问于 2015-11-24 21:54:33
回答 1查看 257关注 0票数 1

有人能告诉我我的代码出了什么问题吗?我已经成功地在标准js文件(SearchResult.view.js)上添加了自定义字段。我知道这不是添加自定义字段的最佳实践。因此,我实现了一个用于添加自定义字段的pre post方法。

不幸的是,当我将我的自定义代码块移动到pre post方法时,它不是添加1行(字段),而是添加了多行。我试着创建一个计数器,但它也不起作用

下面是我的自定义js代码。提前感谢!

代码语言:javascript
复制
function ADDCUSTOMFIELD1(){
 
};
 
ADDCUSTOMFIELD1.prototype.CUSTOM_POST_EXIT = function(methodName,view,controller, methodSignaure) {
 
if (!sap.ui.getCore().byId("ni_home"))
   return;
else add_custom_item();
};
 
 
function add_custom_item(){
if (sap.ui.getCore().byId("subMatrix")){
   // Supplier Name
   matrixSubRow = new sap.ui.commons.layout.MatrixLayoutRow();
   control = new sap.ui.commons.Label({
     text : Appcc.getText("SUPPLIER_TEXT") + ":"
   });// control.addStyleClass("search_middle_spacing");
   matrixCell = new sap.ui.commons.layout.MatrixLayoutCell();
   matrixCell.addContent(control);
   control = new sap.ui.commons.Label();
   control.bindProperty("text", "vendor_name");
   if (sap.ui.getCore().getConfiguration().getRTL()) {
     control.addStyleClass("search_middle_spacingNewRTL");
     Appcc.addStyleClass(control, 'search_middle_spacingNew', true);
   } else
     control.addStyleClass("search_middle_spacingNew");
   matrixCell.addContent(control);
   // control = new sap.ui.commons.Label();
   // control.bindProperty("text", "itm_price");
   // control.addStyleClass("search_middle_spacing");
   // matrixCell.addContent(control);
   matrixSubRow.addCell(matrixCell);
   sap.ui.getCore().byId("subMatrix").addRow(matrixSubRow);
}
 
}

EN

回答 1

Stack Overflow用户

发布于 2016-01-07 23:04:02

您的自定义代码块会添加多行,因为视图上的每个事件都会调用CUSTOM_POST_EXIT函数。单个视图上的多个事件被激发(beforerender、render、ondatamodelloaded等)。methodName参数是事件的名称。尝尝这个

代码语言:javascript
复制
function ADDCUSTOMFIELD1() {};

ADDCUSTOMFIELD1.prototype.CUSTOM_POST_EXIT = function(methodName, view, controller, methodSignaure) {
    var viewId = controller && controller.getView().getId();
    console.log(viewId, methodName)

    if (viewId === 'name_of_your_view' && methodName === 'onDataModelLoaded')
        //implement your customization
    }
}

您应该会看到,页面上的每个视图都会多次调用此函数。

因此,您应该检查调用CUSTOM_POST_EXIT方法的视图和eventName,并仅在一个视图/事件组合中实现您的自定义。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33895488

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档