【发布时间】:2019-03-06 17:22:40
【问题描述】:
我在聚合绑定自定义控件时遇到问题。我无法使用自定义控件内部元素进行双向数据绑定。
自定义控件:
(function(){
"use strict";
var PriceRangeComponent = sap.ui.core.Control.extend('PriceRangeComponent', {
constructor: function(mSettings) {
sap.ui.core.Control.apply(this, arguments);
this.ef = new sap.m.Input({
width: '100px',
value: mSettings.value,
enabled: mSettings.enabled
}).attachChange(function(evt){
console.log(evt);
});
this.setAggregation('_ef', this.ef);
},
metadata: {
properties: {
enabled: { type: 'boolean', defaultValue: true },
value: { type: 'String', defaultValue: "" }
},
events: {
},
aggregations: {
_ef: { type: 'sap.m.Input', multiple: false, visibility: 'hidden' }
}
},
init: function() {
},
renderer: function(oRM, oControl) {
oRM.renderControl(oControl.getAggregation('_ef'));
},
setValue: function (sValue) {
this.ef.setValue(sValue);
},
setEnabled: function (bValue) {
this.ef.setEnabled(bValue);
},
getValue: function(){
return this.ef.getProperty("value");
},
getEnabled: function(){
return this.ef.getProperty("enabled");
}
});
PriceRangeComponent.prototype.clone = function(){
var clone = sap.ui.core.Control.prototype.clone.apply(this, arguments),
bindingInfo;
clone.ef.bindProperty("value",this.getBindingInfo("value"));
return clone;
};
return PriceRangeComponent;
})();
在控件中,我想与外部模型进行两种方式的数据绑定。
自定义控件的使用:
var priceGridwindowShade = new sap.ui.commons.windowshade.WindowShade({
openFirstSection:false,
sections:[],
//layoutData: new sap.ui.layout.GridData({span: "L9 M9"}),
width: "800px",
});
var oTemplateSection = new sap.ui.commons.windowshade.WindowShadeSection({
title: {
parts: [
{path: "startRange"},{path: "endRange"}
],
formatter: function(startRange, endRange){
//console.log(val);
return startRange + " to " + endRange;
}
},
content: [
new PriceRangeComponent({
value: "{startRange}"
}),
new sap.m.Input({ // this input is for checking the 2 way data binding
width: "80px",
value: "{startRange}"
})
]
});
priceGridwindowShade.bindAggregation("sections", {
path: "/items",
template: oTemplateSection,
templateShareable: true});
return priceGridwindowShade;
请帮助我。 当我只是实例化控件并绑定属性时,双向绑定可以正常工作。只是当我进行聚合绑定时它停止工作。
【问题讨论】:
标签: javascript data-binding sapui5