是否可以将控制属性绑定到具有动态属性名称的模型,例如,存储在另一个模型字段中?我认为我们可以为此目的使用SAPUI5 Expression Binding,但它不起作用:跟踪窗口中的绑定被破坏,表达似乎根本没有被评估。
XML视图
MariaDB []> SELECT * FROM mytab;
+------+------+-----------------+------------------+
| Ref | Var | 3SAa combined % | 3SAa combined of |
+------+------+-----------------+------------------+
| AL23 | | 0.00 | 38.78 |
+------+------+-----------------+------------------+
1 row in set (0.00 sec)
MariaDB []> SET @table_name = 'mytab';
Query OK, 0 rows affected (0.00 sec)
MariaDB [bernd]> SET @col_id = 3;
Query OK, 0 rows affected (0.00 sec)
MariaDB []> SELECT DATABASE() INTO @dbname;
Query OK, 1 row affected (0.00 sec)
MariaDB []> SELECT SUBSTRING_INDEX(COLUMN_NAME,' ' , 1) INTO @id_name
-> FROM information_schema.columns
-> WHERE table_schema = @dbname
-> AND TABLE_NAME = @table_name
-> AND ORDINAL_POSITION = @col_id;
Query OK, 1 row affected (0.01 sec)
MariaDB []> SELECT CONCAT('SELECT \'', @id_name, '\' AS Id, ' , GROUP_CONCAT(
-> CONCAT( '`',COLUMN_NAME,'`')
-> , ' AS `', REPLACE(COLUMN_NAME,CONCAT(@id_name,' ') , '')
-> ,'`\n' ), ' FROM ', @table_name) INTO @sql
-> FROM information_schema.columns
-> WHERE table_schema = @dbname
-> AND TABLE_NAME = @table_name
-> ORDER BY ORDINAL_POSITION;
Query OK, 1 row affected (0.01 sec)
MariaDB []> PREPARE stmt FROM @sql;
Query OK, 0 rows affected (0.00 sec)
Statement prepared
MariaDB []> EXECUTE stmt;
+------+------+------+------------+-------------+
| Id | Ref | Var | combined % | combined of |
+------+------+------+------------+-------------+
| 3SAa | AL23 | | 0.00 | 38.78 |
+------+------+------+------------+-------------+
1 row in set (0.00 sec)
MariaDB []> DEALLOCATE PREPARE stmt;
Query OK, 0 rows affected (0.00 sec)
控制器
<TextArea value="{= ${StackOverflow>/bindTextAreaTo} }" />
答案 0 :(得分:7)
不,这是目前无法实现的。
但是,您想要做的事情有一个简单的解决方法(见下文)。 基本上,您创建一个视图模型并在模型上设置一些布尔值。然后在表达式绑定中使用此标志来“动态”定义应使用的模型的属性...
<强> xmlView中强>
<TextArea value="{= ${view>/ask} ? ${StackOverflow>/question} : ${StackOverflow>/comment} }" />
<强>控制器强>
var oModel = this.getView().getModel("StackOverflow");
oModel.setProperty("/question", "");
oModel.setProperty("/comment", "");
//...
var oViewModel = new sap.ui.model.json.JSONModel();
this.getView().setModel(oViewModel, "view);
//...
oViewModel.setProperty("/ask", bAsk);