自 SAPUI5 1.28.20 升级以来,我收到以下错误消息:
代码在 MangedObject.js 中,如下所示:
} else if ( oBindingInfo.templateShareable === MAYBE_SHAREABLE_OR_NOT ) {
// a 'clone' operation implies sharing the template (if templateShareable is not set to false)
oBindingInfo.templateShareable = oCloneBindingInfo.templateShareable = true;
jQuery.sap.log.error("A shared template must be marked with templateShareable:true in the binding info");
}
oBindingInfo.templateShareable
的值为 true
,MAYBE_SHAREABLE_OR_NOT
的值为 1。根据文档,
oBindingInfo.templateShareable
的默认值是 true
。那么这里有什么问题呢?库中的错误?或者我的代码有什么问题?
另见:https://sapui5.netweaver.ondemand.com/sdk/#docs/api/symbols/sap.ui.base.ManagedObject.html
SAPUI5 版本 1.32.x 的更新
在 1.32.x 版本中,消息已更改,现在为:
但根据文档,默认值仍应为 true:
现在看起来,这会产生一些无休止的加载,我一次又一次地收到此消息,直到浏览器崩溃。
任何人都知道可能有什么问题?
最佳答案
上面标记为正确的答案实际上根本不正确,因为这里是错误的:
为了证明你自己上面的答案是错误的,只需运行这个例子(SAPUI5 1.28.20 有相同的结果):
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>SAPUI5 single file template | nabisoft</title>
<script
src="https://openui5.hana.ondemand.com/1.36.12/resources/sap-ui-core.js"
id="sap-ui-bootstrap"
data-sap-ui-theme="sap_bluecrystal"
data-sap-ui-libs="sap.m"
data-sap-ui-compatVersion="edge"
data-sap-ui-preload="async"></script>
<!-- use "sync" or change the code below if you have issues -->
<script>
sap.ui.getCore().attachInit(function () {
"use strict";
var oModel = new sap.ui.model.json.JSONModel({
Items: [
{Name: "Michael"},
{Name: "John"},
{Name: "Frank"},
{Name: "Jane"}
]
});
sap.ui.getCore().setModel(oModel);
var oTemplate = new sap.ui.core.Item({
text : "{Name}"
});
new sap.m.Select({
items : {
path : "/Items",
template : oTemplate
}
}).placeAt("content");
});
</script>
</head>
<body class="sapUiBody">
<div id="content"></div>
</body>
</html>
基本上,UI5 中缺少(或曾经)模板生命周期的明确定义。当检测到这个问题时,周围已经有很多旧的应用程序......所以现在这个新的“功能”是去年某个时候引入的(有点向后兼容)。 UI5 尝试自动检测开发人员对绑定(bind)中使用的给定模板的生命周期的意图(使用一些启发式方法)。如果 UI5 不能清楚地告诉开发人员真正想要什么,那么您将看到此错误日志 - 实际上根本不影响功能。它只是告诉 开发人员 某处有一个模板不会被 UI5 运行时破坏。换句话说, 如果您设置 templateShareable=true 那么您应该确保销毁模板以避免内存泄漏 。所以仅仅设置 templateShareable=true 并不是全部...
我已经发布了一篇关于此的详细博客:Understanding templateShareable in SAPUI5
关于data-binding - 由于templateShareable :true?导致SAPUI5报错的解决方法,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33477355/