我目前正试图扩展sap.m.Input
字段以便能够设置样式和扩展标签位置。 渲染工作正常,但不知何故数据绑定在过程中丢失,我不确定这是为什么。这是我的控制:自定义控件 - 数据绑定不起作用
sap.ui.define([
'sap/m/Input',
], function(Input) {
'use strict';
return Input.extend('one.sj.control.BhTextInput', {
metadata: {
properties: {
label: {
type: 'string',
},
},
aggregations: {
icon: {
type: 'sap.ui.core.Icon',
multiple: false,
visibility: 'public',
},
},
},
renderer: function(oRM, oControl) {
oRM.write('<div class="formControl">');
oRM.write('<input placeholder="'+oControl.getPlaceholder()+'"');
oRM.write('type="'+oControl.getType()+'"');
oRM.write('value="'+oControl.getValue()+'"');
oRM.writeClasses();
oRM.writeControlData(oControl);
oRM.write('/>');
oRM.write('<label class="inputLabel" for="'+oControl.getId()+'"');
oRM.write('>');
oRM.renderControl(oControl.getIcon());
oRM.write('<span class="inputLabelContent">');
oRM.write(oControl.getLabel());
oRM.write('</span>');
oRM.write('</label>');
oRM.write('</div>');
},
});
});
正如你可以看到它很简单。 这是我如何使用它:
<sj:BhTextInput
id="username" class="input textInput"
placeholder="{i18n>HINT_USERNAME}" value="{creds>/username}"
type="Text">
<sj:icon>
<core:Icon src="sap-icon://email" class="inputIcon" />
</sj:icon>
</sj:BhTextInput>
我确认是不是我的模型的一个问题,因为它工作正常,当我更换上面的手动<input/>
建设中renderer
法:
sap.m.InputRenderer.render(oRM, oControl);
你能发现任何错误吗?谢谢!
编辑:澄清一下我的意思是“数据绑定丢失”。当我访问像我这样的控制器内的输入字段的值时,我只会得到一个空字符串:getModel('creds').getProperty('/username');
。这在替换上述手动结构时可以工作。
谢谢。我不知道writeAttribute。可悲的是这并没有改变任何东西。我目前的解决方案只是使用InputRenderer。我相信因为Input并不是实际呈现的,所以输入的onAfterRendering也不会被调用,这可能是某些绑定发生。 – puelo
也许你可以分享你生成的HTML标签? – amiramw