尽管传递了相同的绑定路径,但未调用格式化程序
Formatter not called despite passing the same binding path
我无法解决这个问题。我忽略了什么?
这是一个最小示例:https://plnkr.co/edit/VjqGeG9JpHblyLBb?preview
<tnt:InfoLabel
text="{
path: 'LastName',
formatter: '.formatter.typeText'
}"
colorScheme="{
path: 'LastName',
formatter: '.formatter.typeColor'
}" />
// formatter.js
sap.ui.define([], function () {
"use strict";
return {
typeText: function(sLastName) {
// Called with 'sLastName' value
},
typeColor: function(sLastName) {
// Not called
}
};
});
我正在使用 UI5 1.79 和 sap.ui.model.odata<strong>.v4</strong>.ODataModel
.
将 targetType: 'any'
添加到有问题的 属性 绑定信息中。例如:
<tnt:InfoLabel
文字=“{
路径:'LastName',
格式化程序:'.getMyText'
}”
配色方案="{
路径:'LastName',
格式化程序:'.getMyColorScheme'<strong>,</strong>
<strong>目标类型:'any'</strong>
}”
/>
With sap.ui.model.odata.v4.ODataModel
, data types in property bindings are automatically determined according to the EDM type of the entity property. I.e. in the case above: even without having a certain type
explicitly assigned to the text
property, the v4.ODataPropertyBinding
automatically picks the String
type(因为 LastName
在 $metadata 中有 Type="Edm.String"
)并将其分配给 type
:
<tnt:InfoLabel
文字=“{
路径:'LastName',
格式化程序:'.getMyText',
<em>类型:'sap.ui.model.odata.type.String'</em> <-- v4.ODataPropertyBinding 自动添加
}"
这对 text
属性 没问题,因为它实际上等待 string 值,但对其他属性也是如此,例如 colorScheme
等待 int 值,导致 FormatException。*
为了防止自动Type Determination,必须添加targetType: 'any'
。
* 使用commit:4611772
,从1.80开始可用,我们可以在控制台看到相应的错误信息:
FormatException in property 'colorScheme' of 'Element sap.tnt.InfoLabel#...': <LastName value> is not a valid int value. Hint: single properties referenced in composite bindings and within binding expressions are automatically converted into the type of the bound control property, unless a different 'targetType' is specified. targetType:'any' may avoid the conversion and lead to the expected behavior.
我无法解决这个问题。我忽略了什么?
这是一个最小示例:https://plnkr.co/edit/VjqGeG9JpHblyLBb?preview
<tnt:InfoLabel text="{ path: 'LastName', formatter: '.formatter.typeText' }" colorScheme="{ path: 'LastName', formatter: '.formatter.typeColor' }" />
// formatter.js sap.ui.define([], function () { "use strict"; return { typeText: function(sLastName) { // Called with 'sLastName' value }, typeColor: function(sLastName) { // Not called } }; });
我正在使用 UI5 1.79 和 sap.ui.model.odata<strong>.v4</strong>.ODataModel
.
将 targetType: 'any'
添加到有问题的 属性 绑定信息中。例如:
<tnt:InfoLabel
文字=“{
路径:'LastName',
格式化程序:'.getMyText'
}”
配色方案="{
路径:'LastName',
格式化程序:'.getMyColorScheme'<strong>,</strong>
<strong>目标类型:'any'</strong>
}”
/>
With sap.ui.model.odata.v4.ODataModel
, data types in property bindings are automatically determined according to the EDM type of the entity property. I.e. in the case above: even without having a certain type
explicitly assigned to the text
property, the v4.ODataPropertyBinding
automatically picks the String
type(因为 LastName
在 $metadata 中有 Type="Edm.String"
)并将其分配给 type
:
<tnt:InfoLabel
文字=“{
路径:'LastName',
格式化程序:'.getMyText',
<em>类型:'sap.ui.model.odata.type.String'</em> <-- v4.ODataPropertyBinding 自动添加
}"
这对 text
属性 没问题,因为它实际上等待 string 值,但对其他属性也是如此,例如 colorScheme
等待 int 值,导致 FormatException。*
为了防止自动Type Determination,必须添加targetType: 'any'
。
* 使用commit:4611772
,从1.80开始可用,我们可以在控制台看到相应的错误信息:
FormatException in property 'colorScheme' of 'Element sap.tnt.InfoLabel#...': <LastName value> is not a valid int value. Hint: single properties referenced in composite bindings and within binding expressions are automatically converted into the type of the bound control property, unless a different 'targetType' is specified. targetType:'any' may avoid the conversion and lead to the expected behavior.