SapUI5:如何在MessageStrip中显示sap.m.Link()?

时间:2017-08-23 13:34:49

标签: sapui5

我有一个文本和一个链接到附加到messagestrip,数据附加到模型,但我无法弄清楚如何添加sap.m.Link();所以消息会显示它。

_setAnswerWithLink: function(answerId, objItem, name){
        var oLink = new sap.m.Link();
        oLink.setText(objItem.links[0].title);
        oLink.setHref(objItem.links[0].url);
        oLink.setTarget(objItem.links[0].target);

        var text = objItem.text;

        var oModel = this.fragment.getModel("msgData");
        var oDate = new Date();

        oModel.oData.msgData.push({
            Date: oDate.toLocaleString(),
            Title: "",
            link: oLink,
            Text: text,
            Type : "Success"
        });
            oModel.refresh();
}

这是我的XML文件:

    <List  items="{msgData>/msgData}" >
    <CustomListItem>
        <MessageStrip
            text="{msgData>Text}"
            type="{msgData>Type}"
            showIcon="true"
            showCloseButton="false"
            customIcon="{msgData>customIcon}"
            class="sapUiMediumMarginBottom">
            <link>
                <Link text="test xxxx" /// !!! I NEED HERE THE DATA
                    target="_blank"
                    href="http://www.example.com" />
            </link>
        </MessageStrip>
    </CustomListItem>
</List>

如何设置链接并在xml上解析它?

1 个答案:

答案 0 :(得分:1)

我会尝试这个。 控制器片段:

_setAnswerWithLink: function(answerId, objItem, name){
        /* You don't need to create sap.m.Link instance, data binding should do it
        var oLink = new sap.m.Link();
        oLink.setText(objItem.links[0].title);
        oLink.setHref(objItem.links[0].url);
        oLink.setTarget(objItem.links[0].target);
        */

        var text = objItem.text;

        var oModel = this.fragment.getModel("msgData");
        var oDate = new Date();

        // If property msgData is not set, then we have an empty array
        var aMsgData = oModel.getProperty("/msgData") || [];

        // Don't update model data via oData, do it ether by setData or by setProperty
        // oModel.oData.msgData.push({
        aMsgData.push({
            Date: oDate.toLocaleString(),
            Title: "",
            link: { 
              title: objItem.links[0].title,
              url: objItem.links[0].url,
              target: objItem.links[0].target
             },
            Text: text,
            Type : "Success"
        });

        oModel.setProperty("/msgData", aMsgData);
}

和XML视图:

<List  items="{msgData>/msgData}" >
    <CustomListItem>
        <MessageStrip
            text="{msgData>Text}"
            type="{msgData>Type}"
            showIcon="true"
            showCloseButton="false"
            customIcon="{msgData>customIcon}"
            class="sapUiMediumMarginBottom">
            <link>
                <Link text="{msgData>link/title}" /// !!! I NEED HERE THE DATA
                    target="{msgData>link/target}"
                    href="{msgData>link/url}" />
            </link>
        </MessageStrip>
    </CustomListItem>
  </List>