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

时间:2016-02-12 19:58:22

标签: javascript sapui5

When attempting to attach a custom data attribute to a table column using an XML view, I am receiving the following error in the Chrome browser console:

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. - 

My column definition is as follows:

<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>

The attribute is actually correctly written out to the DOM, but it seems as if the error message should not occur as I am indeed passing a string value for the "value" attribute of the custom data object. I also tried hard coding the "value" attribute of the custom data object to "test" thinking it might be a data binding related issue, but got the same result.

As the data attribute is actually being correctly written out to the DOM, this is more of an annoyance than a blocking issue. I am wondering if this is a result of me not using custom data correctly in my XML view, as I am pretty new to openui5.

Thanks, Matt

1 个答案:

答案 0 :(得分:0)

使用绑定格式化程序。将某行中的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;
        }
    };
});