SAPUI5アプリケーションでoDataサービスを使用して新しいエントリを作成する簡単なフォームを作成します。私のアプローチは、以下のようなダイアログを作っている:SAPUI5のXMLビューのjsコントローラで生成されたダイアログを使用してフォームを送信
<core:FragmentDefinition xmlns="sap.m" xmlns:core="sap.ui.core">
<Dialog id="CreateDialog" title="Add New Employee">
<content>
<Button id="bt" text="s"></Button>
<sap.ui.layout.form:Form editable="true" xmlns:sap.ui.layout.form="sap.ui.layout.form" id="__form4">
<sap.ui.layout.form:formContainers>
<sap.ui.layout.form:FormContainer title="Title" id="__container4">
<sap.ui.layout.form:formElements>
<sap.ui.layout.form:FormElement label="Employee ID" id="__element5">
<sap.ui.layout.form:fields>
<Input width="100%" id="txtEmpid" placeholder="Emp ID"/>
</sap.ui.layout.form:fields>
</sap.ui.layout.form:FormElement>
</sap.ui.layout.form:formElements>
</sap.ui.layout.form:FormContainer>
</sap.ui.layout.form:formContainers>
<sap.ui.layout.form:layout>
<sap.ui.layout.form:ResponsiveGridLayout id="__layout3"/>
</sap.ui.layout.form:layout>
</sap.ui.layout.form:Form>
<Button id="_btnSubmit" text="Submit" press="submitDialog"/>
</content>
</Dialog>
私はid ="txtEmpid"
与えられたid="bt"
入力テキストを与えられたボタンがある簡単なフォームを作成しました。私の問題は私のコントローラでこのIDに到達できないということです。これは私が試みた方法です:私はpress=submitDialog
を与えるボタンを追加し、全体のビューを作成したコントローラ内のメソッド(idでコントロールを取得し、単にテキストを変更する)を実装します。
sap.ui.define(["sap/ui/core/mvc/Controller"], function(Controller) {
"use strict";
return Controller.extend("Demo1.controller.InitView", {
showCreateDialog: function() {
var view = this.getView();
var createDialog = view.byId("CreateDialog");
var oDummyController = {
// This is when I clicked the Submit button in dialog
submitDialog: function() {
var button = this.getView().byId("bt");
var inputText = this.getView().byId("txtEmpid");
// I tried to test if I reached these controls by byId method
button.setText("ssss");
inputText.setValue("zzz");
},
closeDialog: function() {
createDialog.close();
}
};
// This is when the dialog event is fired, things are fine here
if (!createDialog) {
createDialog = sap.ui.xmlfragment(view.getId(), "Demo1.view.CreateDialog", oDummyController);
}
view.addDependent(createDialog);
createDialog.open();
if (!createDialog.isOpen()) {
//do sth
}
}
});
});
私がコントロールに達するだけでなく、そのテキストを変更することはできませんどのようなhappern、これはErrorで見てみました。
任意の提案、
よろしく、
おかげでたくさんのようにそれを使用します。あなたの方法は今私の新しいベストプラクティスです –
あなたは大歓迎です。そして、Udacityの「Object Oriented Javascript」コースの「Scope」と「this keyword」の部分を見てみましょう。私はそれがあなたにとって非常に役に立つと確信しています。 –