在 XML 视图中将静态值传递给格式化程序参数

ale*_*exP 6 sapui5

我想getCountdown用两个参数调用函数:

  • 第一个 (AuctionEnd) 是来自模型的动态。
  • 第二个应该在"Time"或 中硬编码"Status"

这是我的代码:

<ObjectStatus
  title="Time"
  text="{
    parts: [
      {path: 'AuctionEnd'},
      {path: 'Time'}
    ],
    formatter: '.formatter.getCountdown'
  }"
/>
Run Code Online (Sandbox Code Playgroud)

在 formatter.js 中,只有在我的控制台日志中看到的第一个参数:

["2016-05-20T12:00:00", undefined]
Run Code Online (Sandbox Code Playgroud)

在 JS 中,我会这样做:

["2016-05-20T12:00:00", undefined]
Run Code Online (Sandbox Code Playgroud)

Bog*_*ann 13

从 UI5 1.61 (commit) 开始,您可以向绑定信息对象添加静态值。语法是value代替path.

parts: [
  { path: '/modelPath' },
  { value: 123 }
],
Run Code Online (Sandbox Code Playgroud)

与 相同path,您可以value使用更多设置来增强绑定信息,如本演示所示 ==> https://jsbin.com/yeguhow/edit?js,output



? UI5 1.79 及以下版本中的错误

正如在GitHub 问题 #2916上报告的那样,有一个错误在 UI5 1.80 中首先被修复。
考虑将添加作为临时解决方案,或从(从默认模型绑定)中删除模型名称以规避该问题。{ value: 123, model: <modelName> }path


hir*_*rse 0

据我所知,您不能将静态部分添加到格式化程序,它只能采用模型值。有关属性中动态和静态部分的组合,请参阅表达式绑定复杂绑定语法

对于您的情况,您可以添加两个更专门的格式化程序函数并调用您需要的函数:

<ObjectStatus text="{parts: ['AuctionEnd'], formatter: '.formatter.getCountdownTime'}" />
Run Code Online (Sandbox Code Playgroud)

(您可以在零件数组中提供路径字符串数组。)

formatter.getCountdownTime = function (auctionEnd) {
    return formatter.getCountdown(auctionEnd, "Time");
}

formatter.getCountdownStatus = function (auctionEnd) {
    return formatter.getCountdown(auctionEnd, "Status");
}
Run Code Online (Sandbox Code Playgroud)