Sapui5 为什么在自定义控件中呈现的UI5控件不会在属性更改时重新呈现?
我创建了一个自定义控件Sapui5 为什么在自定义控件中呈现的UI5控件不会在属性更改时重新呈现?,sapui5,Sapui5,我创建了一个自定义控件my.control,它直接呈现sap.m.Text,并通过聚合接收另一个 为了简单起见,将示例粘贴到一个文件中: <html> <head> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta http-equiv="Content-Type" content="text/h
my.control
,它直接呈现sap.m.Text
,并通过聚合接收另一个
为了简单起见,将示例粘贴到一个文件中:
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
<title>SAPUI5 example</title>
<script id="sap-ui-bootstrap"
src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js"
data-sap-ui-theme="sap_belize"
data-sap-ui-libs="sap.m, sap.ui.core"
data-sap-ui-compatVersion="edge"
data-sap-ui-async="true">
</script>
<script>
sap.ui.getCore().attachInit(function () {
sap.ui.core.Control.extend("my.Control", {
metadata: {
aggregations: {
testControl: {
type: 'sap.m.Text',
multiple: false,
singularName: 'testControl'
}
}
},
renderer: function (oRm, oControl) {
oRm.openStart('div', oControl);
oRm.openEnd();
oRm.text('DIRECTLY GENERATED CONTROL : ');
oRm.renderControl(new sap.m.Text('direct-control', {text: 'initial value'}));
oRm.openStart('br');
oRm.openEnd();
oRm.text('AGGREGATION PASSED CONTROL : ');
oRm.renderControl(oControl.getTestControl());
oRm.close('div');
}
});
new my.Control({
testControl: [
new sap.m.Text('passed-control', {text: 'initial value'})
]
}).placeAt('content');
});
</script>
</head>
<body class="sapuiBody" id="content">
</body>
</html>
SAPUI5示例
sap.ui.getCore().attachInit(函数(){
sap.ui.core.Control.extend(“my.Control”{
元数据:{
聚合:{
测试控制:{
键入:“sap.m.Text”,
多重:假,
名称:“testControl”
}
}
},
渲染器:函数(oRm、oControl){
oRm.openStart('div',oControl);
oRm.openEnd();
oRm.text('直接生成的控件:');
oRm.renderControl(新的sap.m.Text('direct-control',{Text:'initial value'}));
oRm.openStart('br');
oRm.openEnd();
oRm.text('聚合已通过控制:');
oRm.renderControl(oControl.getTestControl());
格式关闭(“div”);
}
});
新的,我的控制({
测试控制:[
new sap.m.Text('passed-control',{Text:'initial value'})
]
}).placeAt(“内容”);
});
两个负载都正常。但当通过Javascript编辑其文本属性时,传递的控件将被更新,而另一个控件则不会:
sap.ui.getCore().byId('passed-control').setText('edited value')
控件被重新命名
sap.ui.getCore().byId('direct-control').setText('edited value')
控件未重新提交
如果我执行sap.ui.getCore()
为什么他们的行为不同?
有没有办法配置此行为
谢谢。testControl
聚合在您的自定义控件中,这在它们之间带来了父子关系。当子属性发生更改时,其父属性也会失效。另一方面,每次调用render()时,都会创建新的direct control
。testControl
会聚合到自定义控件中,这会在它们之间产生父子关系。当子属性发生更改时,其父属性也会失效。另一方面,每次调用render()时,都会创建新的直接控制。