on 10-08-2015 4:07 PM
Hello!
Please tell me where I'm wrong.
I have created a component multiple angles and multiple controllers. I added an attribute 'main_data' to the component.
If I call this attribute in the code fragment, everything works correctly.
MonoTable_Edit.fragment.js
sap.ui.jsfragment("sap.ui.....forms.view.MonoTable_Edit", {
createContent: function(oController) {
var oDFC = oController.getOwnerComponent().main_data;
...
If I call this attribute in the code of the controller, the console browser (FireFox) I get the error:
"TypeError: this.getOwnerComponent is not a function"
MonoTable.controller.js
addNewEntry: function(){
var o_entry;
var component;
component = this.getOwnerComponent();
o_entry = component.main_data.output.lines[0];
...
Tell me, how else can you turn to the component from controller?
Hi,
Try this:
var sComponentId = sap.ui.core.Component.getOwnerIdFor(this.getView());
var comp = sap.ui.component(sComponentId);
I used above statements to get component and called method on it.
Thanks,
Dheeram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, Dheeram!
Now the console browser displays an error:
TypeError: this.getView is not a function
Perhaps should clarify the implementation of the controller:
MonoTable.controller.js
sap.ui.define([
'jquery.sap.global',
'sap/m/MessageToast',
'sap/ui/core/Fragment',
'sap/ui/core/mvc/Controller',
'sap/ui/model/json/JSONModel'
], function(jQuery, MessageToast, Fragment, Controller, JSONModel) {
"use strict";
var MonoTableController = Controller.extend("sap.ui.x5.forms.controller.MonoTable", {
onInit: function() {
//...
},
onExit : function () {
//...
},
//...
testMethod: function(){
var sComponentId = sap.ui.core.Component.getOwnerIdFor(this.getView());
var comp = sap.ui.component(sComponentId);
var s_tmp = comp.test_attribute;
MessageToast.show(s_tmp);
},
});
return MonoTableController;
});
Hello again, Maksim!
I call the method by pressing a button. Button is located in the fragment.
MonoTable_Edit.fragment.js
sap.ui.jsfragment("sap.ui.....forms.view.MonoTable_Edit", {
createContent: function(oController) {
//...
oButtonNewEntry = new sap.m.Button({
text: "Press me",
press: oController.testMethod
})
oToolBar = new sap.m.Toolbar({
content:[
oButtonNewEntry
]
});
oLayout = new sap.ui.layout.VerticalLayout("LayoutForMonoTableEdit", {
content:[
//...
oToolBar
]
});
return oLayout;
}
});
press: jQuery.proxy(oController.testMethod , oController)
or
press: [oController.testMethod , oController]
User | Count |
---|---|
85 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.