Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

combobox - UI5: Why is the formatter called a second time with a 'null' value?

I'm using a XML-Fragment defining a ComboBox where I want to add some core:CustomData with a value returned by a formatter. The formatter is called the first time when the fragment shows up and a second time when I open the dropdown list of the combobox. First time I get a single entry(from entries) from the model as expected. At the second call the parameter is null.

What am I doing wrong?

'myModel' is a static json model loaded via manifest.json:

{
 "entries": [
    {
        "title": "first entry",
        "hide": false,
        "id": 1
    },
    {
        "title": "second entry",
        "hide": true,
        "id": 2
    }
 ]
}

The ComboBox defined inside a FragmentDefinition inside a Popover:

               <ComboBox id="xys" selectedKey="{myModel>/aKey}" value="{myModel>/aValue}"
                    items="{myModel>/entries}">
                    <core:ListItem key="{myModel>id}" text="{path: 'myModel>', formatter: '.entryTextFormatter'}" >
                        <core:customData>
                            <core:CustomData key="hide-item" value="{path: 'myModel>', formatter: '.hideItemFormatter'}" writeToDom="true"/>
                        </core:customData>
                    </core:ListItem>
                </ComboBox>

And the formatter code looks like:

/* Test cases */
entryTextFormatter: function(entry) {
    return entry.title;
},
hideItemFormatter: function(entry) {
    if(entry && (entry.hide == true)) {
        return "true";
    } else {
        return "false";
    }
},

Edit: Note! If using the same formatter for the CustomData and the ListItem it is only called twice for the CustomData.

Does anyone has an idea why the formatter gets null as parameter the second time?

question from:https://stackoverflow.com/questions/65923710/ui5-why-is-the-formatter-called-a-second-time-with-a-null-value

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...