共享模板必须标记为 templateShareable:true 错误 [英] Shared Template Must Be Marked with templateShareable:true Error

查看:73
本文介绍了共享模板必须标记为 templateShareable:true 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 SAPUI5 创建一个应用程序(我是这个库的新手),但我遇到了以下奇怪的错误:

I am creating an application with SAPUI5 (I am new with this library) and I run to the following strange error:

共享模板必须在绑定信息中标记为 templateShareable:true -

A shared template must be marked with templateShareable:true in the binding info -

Codewise,原因是在cartelleDisponibili:cartelleObtained下面的Promise里面:

Codewise, the cause is to be found in cartelleDisponibili: cartelleObtained inside the following Promise:

new Promise(
  function(resolve, reject) {
    cartellaData.results.forEach((cartella, index) => {
      oModel.read("/SheetSet", {
        filters: [
          new sap.ui.model.Filter("ZUSERNAME", sap.ui.model.FilterOperator.EQ, userData.Username),
          new sap.ui.model.Filter("ZTYPE", sap.ui.model.FilterOperator.EQ, 'P'),
          new sap.ui.model.Filter("ZCARTELLA", sap.ui.model.FilterOperator.EQ, cartella.ZCARTELLA),
        ],
        success: function(sheetData){
          var sheetsResults = [];
          for(var sheet = 0; sheet < sheetData.results.length; sheet++){
            sheetsResults.push({
              "Sheet": sheetData.results[sheet].ZSHEET,
              "CanWrite": sheetData.results[sheet].ZCANWRITE ? true : false, 
            });
          }
          cartelle.push({
            "Cartella": cartella.ZCARTELLA,
            "CanWrite": cartella.ZCANWRITE ? true : false,
            "Sheets": sheetsResults,
          });
        },
        error: function(oEvent) {}
      });
    });
  resolve(cartelle);
}).then(function(cartelleObtained) {
  var selectedUser = {
    title: `Utente ${userData.Username}`,
    editUsername: false,
    progNavi: false,
    progProd: true,
    userMainCredentials: {
      userName: userData.Username,
      type: "P",
      isEnabled: userData.isAbilitato,
      isAdmin: userData.isAdmin,
      firstName: userData.Nome,
      lastName: userData.Cognome,
    },
    cartelleDisponibili: cartelleObtained,
  };
  var oJSONModelNewUser = new JSONModel(selectedUser);
  _this.getView().setModel(oJSONModelNewUser, "userModel");
  if (!_this._dShowUser) {
    _this._dShowUser = sap.ui.xmlfragment("cabot.ui.wt.fragment.ShowUser", _this);
    _this.getView().addDependent(_this._dShowUser);
  }
  _this._dShowUser.open();
});

如果我直接向 cartelleDisponibili 传递一个项目数组,则不会抛出错误.我还需要解决这个问题,因为这会导致 UI 中出现一些奇怪的行为.我该如何解决这个问题?

If I pass to cartelleDisponibili an array of items directly, the error is not thrown. I need to fix this issue also because this is causing some little odd behavior in the UI. How can I solve this issue?

推荐答案

您必须使用旧版本的 UI5.至少,错误消息不再是源代码的一部分自 1.38 起.改进后的错误消息说得更多:

You must be using an old version of UI5. At least, the error message is not part of the source code anymore since 1.38. The improved error message says a bit more:

在克隆操作期间,发现模板既未标记为templateShareable:true",也未标记为templateShareable:false".框架不会破坏模板.这可能会导致错误(例如重复的 ID)或内存泄漏.

During a clone operation, a template was found that neither was marked with 'templateShareable:true' nor 'templateShareable:false'. The framework won't destroy the template. This could cause errors (e.g. duplicate IDs) or memory leaks.

这表明,在某处,您还必须在控件中定义一个聚合绑定,该控件用作更高层次结构级别中另一个聚合绑定的模板.

This indicates that, somewhere, you also must be defining an aggregation binding inside a control which is used as a template for another aggregation binding in an upper hierarchy level.

消除错误信息有两种解决方案(取决于您想要什么):

There are two solutions to get rid of the error message (depending on what you want):

  • 如果您想更好地控制模板控件的生命周期,请在每个聚合绑定信息对象.
  • 但是,如果您不自己处理此类模板,请让 UI5 通过在每个聚合绑定信息对象中显式禁用 templateShareable(值为 false)来处理它们.
  • If you want to have more control over the lifecycle of your template control(s), enable templateShareable (with value true) explicitly in each aggregation binding info object.
  • However, if you do not take care of such templates by yourself, let UI5 handle them by explicitly disabling templateShareable (with value false) in each aggregation binding info object.

有关更多信息,请查看文档绑定模板的生命周期 以及 这篇博文Nabi.

For more information, take a look at the documentation Lifecycle of Binding Templates and at this blog post by Nabi.

这篇关于共享模板必须标记为 templateShareable:true 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆