我有一个包含3列的表,其中一列是复选框,一列是输入,第三列是简单文本。每当一个人在输入中输入一个值时,我想要选中该行的复选框。以下是我提取输入的输入方式。
inputChange: function(oEvent) {
var a = oEvent.getSource();
var input = a.getValue();
var row = oEvent.getSource().getParent().getParent();
var index = row.getIndex();
// ...
}
我有行索引,但我不知道如何遍历该行的复选框并选中复选框。如何构建该语法?
答案 0 :(得分:2)
尝试使用expression binding:
,而不是遍历单元格列表或通过多个getParent
调用访问行
<CheckBox selected="{= !!${myModel>thatInputValue}}" />
Binding允许我们将数据与UI结构分开(松散耦合)。当模型中的selected
更新时,框架将负责更新thatInputValue
值(可以通过双向数据绑定或通过myModel.setProperty
完成)。
答案 1 :(得分:0)
这是一种(不是非常有效)的方式,它接近你正在尝试的方式。 但是,我建议将Boghyon的解决方案作为一种良好的做法。
1. Get the row Index you are working on
var rowIndex = oEvent.getSource().getParent().getBindingContextPath().split("/")[2]; <--- split this code into multiple lines if does not work in one.
2. Get the checkBox control of the selected Row using the table.
var oChewckBox = this.getView().byId("TableId").getAggregation("items")[rowIndex].getAggregation("cells")[0<this should be the column number in your table>]
3. Make the checkBox Selected.
oCheckBox.setSelected(false)
如果这有帮助,请告诉我。
答案 2 :(得分:0)
在XML中创建一个复选框绑定的属性。
然后,您可以使用此代码在按钮单击时将属性设置为true或false。
<button onclick="myFunction()">Click me</button>
<p id="demo"></p>
如果您需要有关物业装订的任何帮助,请与我们联系。在没有看到更多代码的情况下,我很难解释这一部分。