sapui5 - 如何将 SAP UI5 控件附加到单选按钮控件
问题描述
我有一个扩展 sap.m.RadioButton 的自定义单选按钮 js 类。在它的属性中我有一个控件,我想将该控件附加到单选按钮。radioButton 正在 radioButtonGroup 控件中使用。
假设我想将输入控件附加到单选按钮我的输入如下
let oInput = new sap.m.Input({
width: "100%",
type: sap.m.InputType.Text,
enabled: true
});
//adding then input to radiobutton - this refers to radiobutton
this.$().append("<div>" + oInput + "</div>");
这不能按照我想要的方式工作,因为我看到诸如“Element sap.m.Input#__input22”之类的文本被附加到控件中。我试图做这样的事情:
this.$().append("<div>" + oInput.getDomRef() + "</div>");
并没有工作。有小费吗 ?
谢谢你
解决方案
创建复合控件可能比扩展 RadioButton 控件更容易,例如https://jsbin.com/puqopam/edit?js,output
sap.ui.define([
'sap/ui/core/Control',
'sap/ui/model/json/JSONModel',
'sap/m/RadioButton',
'sap/m/Input'
], function (Control, JSONModel, RadioButton, Input) {
Control.extend('RadioButtonEx', {
metadata: {
aggregations: {
radio: { type: 'sap.m.RadioButton', multiple: false },
input: { type: 'sap.m.Input', multiple: false }
},
},
renderer: function (rm, oControl) {
rm.write('<div');
rm.writeControlData(oControl);
rm.write('>');
rm.write('<div>');
rm.renderControl(oControl.getAggregation('radio'));
rm.write('</div>');
rm.write('<div>');
rm.renderControl(oControl.getAggregation('input'));
rm.write('</div>');
rm.write('</div>');
}
});
var combo = new RadioButtonEx({
radio: new RadioButton({
text: "test"
}),
input: new Input()
});
combo.placeAt("content")
});
推荐阅读
- google-app-maker - Google App Maker:如何更新一个字段的多行?
- python-3.x - 调度动作
- html - HTML 画布:如何创建一个填充有网格的多边形
- javascript - 多个 jQuery 正则表达式测试
- ios - 在 swift 4 中添加/更新自定义对象字典数组
- php - 如何以安全的方式存储我的客户的 API 密钥?
- java - 每次打开片段时都会调用任何生命周期方法吗?
- javascript - 类型“{}”不可分配给类型“只读”
' - java - 如何使用 RxJava 过滤列表并将所有匹配的元素分组
- laravel - Laravel:禁止用户直接访问 Post 方法