如何通过 ID 从弹出片段访问控制
How to access control from the popup fragment by ID
我希望在按下 确定 按钮后我的文本区域为空。
我试过这条线this.byId("id").setValue("")
onWorkInProgress: function (oEvent) {
if (!this._oOnWorkInProgressDialog) {
this._oOnWorkInProgressDialog = sap.ui.xmlfragment("WIPworklist", "com.sap.FinalAssestments.view.WorkInProgress", this);
//this.byId("WIP").value = "";
//this.byId("WIP").setValue();
this.getView().addDependent(this._oOnWorkInProgressDialog);
}
var bindingPath = oEvent.getSource().getBindingContext().getPath();
this._oOnWorkInProgressDialog.bindElement(bindingPath);
this._oOnWorkInProgressDialog.open();
},
//function when cancel button inside the fragments is triggered
onCancelApproval: function() {
this._oOnWorkInProgressDialog.close();
},
//function when approval button inside the fragments is triggered
onWIPApproval: function() {
this._oOnWorkInProgressDialog.close();
var message = this.getView().getModel("i18n").getResourceBundle().getText("wipSuccess");
MessageToast.show(message);
},
文本区域将在片段中弹出。我希望文本区域为空。
我想你差不多做到了。只是把
this.byId("WIP").setValue("")
行在 if()
块之后。由于您将片段添加为视图的依赖项,因此每次您打开 WIP 片段并将其值设置为空白时,this.byId("WIP")
都会找到 ID 为 "WIP"
的控件。
您现在可能无法实现它,因为 A. 它还不是您视图的依赖项,并且 B. 它只会在第一个 go-around.
时被解雇
如果你像这样实例化你的片段:
sap.ui.xmlfragment("WIPworklist", "com.sap.FinalAssestments.view.WorkInProgress", this);
您可以像这样访问它的控件:
Fragment.byId("WIPworklist", "WIP").setValue(""); // Fragment required from "sap/ui/core/Fragment"
来源:
更好的方法是使用视图模型。模型应该有一个 属性 textAreaValue
或类似的东西。
然后将 属性 绑定到您的 TextArea (<TextArea value="{view>/textAreaValue}" />
)。如果您使用代码更改值(例如 this.getView().getModel("view").setProperty("/textAreaValue", "")
),它将自动在您的弹出窗口中显示新值。
它是双向工作的:如果用户更改文本,它将在视图模型中自动更新,因此您可以使用 this.getView().getModel("view").getProperty("/textAreaValue");
.
访问新值
我希望在按下 确定 按钮后我的文本区域为空。
我试过这条线this.byId("id").setValue("")
onWorkInProgress: function (oEvent) {
if (!this._oOnWorkInProgressDialog) {
this._oOnWorkInProgressDialog = sap.ui.xmlfragment("WIPworklist", "com.sap.FinalAssestments.view.WorkInProgress", this);
//this.byId("WIP").value = "";
//this.byId("WIP").setValue();
this.getView().addDependent(this._oOnWorkInProgressDialog);
}
var bindingPath = oEvent.getSource().getBindingContext().getPath();
this._oOnWorkInProgressDialog.bindElement(bindingPath);
this._oOnWorkInProgressDialog.open();
},
//function when cancel button inside the fragments is triggered
onCancelApproval: function() {
this._oOnWorkInProgressDialog.close();
},
//function when approval button inside the fragments is triggered
onWIPApproval: function() {
this._oOnWorkInProgressDialog.close();
var message = this.getView().getModel("i18n").getResourceBundle().getText("wipSuccess");
MessageToast.show(message);
},
文本区域将在片段中弹出。我希望文本区域为空。
我想你差不多做到了。只是把
this.byId("WIP").setValue("")
行在 if()
块之后。由于您将片段添加为视图的依赖项,因此每次您打开 WIP 片段并将其值设置为空白时,this.byId("WIP")
都会找到 ID 为 "WIP"
的控件。
您现在可能无法实现它,因为 A. 它还不是您视图的依赖项,并且 B. 它只会在第一个 go-around.
时被解雇如果你像这样实例化你的片段:
sap.ui.xmlfragment("WIPworklist", "com.sap.FinalAssestments.view.WorkInProgress", this);
您可以像这样访问它的控件:
Fragment.byId("WIPworklist", "WIP").setValue(""); // Fragment required from "sap/ui/core/Fragment"
来源:
更好的方法是使用视图模型。模型应该有一个 属性 textAreaValue
或类似的东西。
然后将 属性 绑定到您的 TextArea (<TextArea value="{view>/textAreaValue}" />
)。如果您使用代码更改值(例如 this.getView().getModel("view").setProperty("/textAreaValue", "")
),它将自动在您的弹出窗口中显示新值。
它是双向工作的:如果用户更改文本,它将在视图模型中自动更新,因此您可以使用 this.getView().getModel("view").getProperty("/textAreaValue");
.