我认为你处理这个问题的方式是错误的。sap.m.Switch
已经有一个属性来指示可以直接绑定到模型的状态。
<Switch state="{IsPersonActive}" />
假设您将表中的项目绑定到未命名的模型,这将设置IsPersonActive
绑定线上的标志true
or false
取决于开关的状态。
这也意味着如果确定的话,开关会处于正确的状态IsPersonActive
实体集中的标志已设置为 true 或 false。
(…) 数据来自数据库1
/0
, 而不是true
/false
(…).
更改后是否有更新模型的标准方法sap.m.Switch
value?
双向数据绑定修复https://embed.plnkr.co/wwQXf8bTuiTP4RlP https://embed.plnkr.co/wwQXf8bTuiTP4RlP?show=index.html,model%2Ftype%2FNumericBoolean.js,preview:
数字布尔值.js(最小示例):
sap.ui.define([
"sap/ui/model/SimpleType",
], Type => Type.extend('demo.model.type.NumericBoolean', {
constructor: function() {
Type.apply(this, arguments);
},
formatValue: iValue => !!+iValue,
parseValue: bValue => bValue ? 1 : 0,
validateValue: vValue => { /*validate...*/ },
}));
<Switch xmlns="sap.m" xmlns:core="sap.ui.core"
core:require="{ NumericBoolean: 'demo/model/type/NumericBoolean' }"
state="{
path: '/1or0',
type: 'NumericBoolean'
}"
/>
重要的提示:
必须保留validateValue
即使未提供实现也需声明,否则sap.m.Switch
将无法正常工作。