SAP openui5:将自定义数据附加到表列模板时出错

SAP openui5: Error when attaching customData to a table column template

本文关键字:出错 openui5 自定义 数据 SAP      更新时间:2023-09-26

尝试使用 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"属性进行硬编码以"测试",认为这可能是与数据绑定相关的问题,但得到了相同的结果。

由于数据属性实际上被正确地写出到 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;
    }
});

或查看格式化程序。请参阅步骤 23:自定义格式化程序。

sap.ui.define([], function () {
    return {
        customDataFormatter: function (value) {
            if (!value) {
                value = '';
            }
            return value;
        }
    };
});