如何将多个属性绑定连接为一个 [英] How to concatenate multiple property bindings into one

查看:51
本文介绍了如何将多个属性绑定连接为一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 OData 源,它提供包含 first_name & 的结果行.姓氏.

I have an OData source that gives result rows that contain first_name & last_name.

我想在一个表格中显示这些内容,其中有一列名为全名.

I want to display these in a table with a column called Full Name.

我正在尝试使用 JSView(它似乎不像 XML 那样笨拙).

I'm trying to use a JSView (It seems less kludgy than XML).

我可以像这样进行 1:1 绑定:

I can do a 1:1 binding like this:

var template = new sap.m.ColumnListItem({
  // ...,
  cells: [
    new sap.m.Text({
      text: "{first_name}"
    })
  ]
});

但我不知道如何将多个字段绑定/连接到 Text 控件,或者如何将多个 Text 控件放入一个单元格中.

But I cannot figure out how to bind / concatenate multiple fields to the Text control, or alternatively how to put multiple Text controls into one cell.

这与其他建议的解决方案不完全相同,因为这是针对 JSView 而不是 XMLView.

This is not the exact same as the other suggested solution because this is for JSView instead of XMLView.

推荐答案

这花了我几个小时的搜索和反复试验,但我终于找到了使用格式化程序回调的方法:

This took me several hours of searching and trial and error, but I finally figured out out to use a formatter callback:

    var template = new sap.m.ColumnListItem({
        id: "column_template",
        type: "Navigation",
        visible: true,
        cells: [
            new sap.m.Text("activity", {
                text:  {
                    parts: [
                        {path: "first_name"},
                        {path: "last_name"}
                    ],
                    formatter: function(a,b){
                        return a+" "+b;
                    }
                }
            })
        ]
    });

parts 显然必须是具有 path 属性的对象数组.路径值必须与 odata 源匹配.

parts must apparently be an array of objects with a path property. The path value must match the odata source.

然后这些值将作为参数传递给 formatter 回调.

These values will then be passed to the formatter callback as arguments.

您也可以使用模板进行简单的连接,但有一个技巧 - 您必须将 data-sap-ui-compatVersion="edge" 添加到您的引导程序,然后以下将工作:

you can also do simple concatenation with a template, but there is a trick - you must add data-sap-ui-compatVersion="edge" to your bootstrap and then the following will work:

new sap.m.Text("activity", {
    text: "{first_name} {last_name}"
});

这篇关于如何将多个属性绑定连接为一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆