尝试使用XML视图将自定义数据属性附加到表列时,我在Chrome浏览器控制台中收到以下错误:
2016-02-12 12:02:38.331040 CustomData with key strikethrough should be written to HTML of Element sap.m.Text#__text10-col1-row6 but the value is not a string. -
我的列定义如下:
<table:Column width="200px">
<Label text="Plant Variation"/>
<table:template>
<Text text="{__textpvvalue__}">
<customData>
<core:CustomData key="strikethrough" value="{__rowstyle__}" writeToDom="true" />
</customData>
</Text>
</table:template>
</table:Column>
该属性实际上已正确写入DOM,但似乎不应出现错误消息,因为我确实传递了自定义数据对象的“value”属性的字符串值。我还尝试将自定义数据对象的“value”属性硬编码为“test”,认为它可能是与数据绑定相关的问题,但得到的结果相同。
由于数据属性实际上正确地写入DOM,这比阻塞问题更令人烦恼。我想知道这是不是因为我没有在我的XML视图中正确使用自定义数据,因为我对openui5很新。
谢谢,马特
使用绑定格式化程序。将某些行中的null
值格式化为空字符串。
var customData = new sap.ui.core.CustomData({
key: 'strikethrough',
writeToDom: true
});
customData.bindProperty('value', {
path: '__rowstyle__',
formatter: function (value) {
if (!value) {
value = '';
}
return value;
}
});
或者查看格式化程序。见Step 23: Custom Formatters。
sap.ui.define([], function () {
return {
customDataFormatter: function (value) {
if (!value) {
value = '';
}
return value;
}
};
});