Super-stupid question, but I can't make it work, how do we call a function from another function within the same Controller
? I use sencha architect.
Here is my controller where I a have a listener and a function, I want to call generateField
function from the listener
Ext.define('Medlemssystem.controller.MemberOrganisationController', {
extend: 'Ext.app.Controller',
views: [
'LocalOrgPanel'
],
onLocalOrganisationInfoAfterRender: function(ponent, eOpts) {
main_id = ponent.up('#memberTab').main_id;
ponent.removeAll();
Ext.Ajax.request({
url: 'OrganizationCustomFieldServlet',
method: 'GET',
dataType: 'json',
params: {
"operation" : "get",
"org_id" : main_id
},
success: function(response) {
var result = Ext.decode(response.responseText);
result.forEach(function(n) {
ponent.add(generateField(n.customField.name));
});
},
failure: function() {
console.log('woops');
}
});
},
generateField: function(name, type, id, required, description) {
var field = Ext.create("Ext.form.field.Text", {fieldLabel:name});
return field;
},
init: function(application) {
this.control({
"LocalOrgPanel": {
afterrender: this.onLocalOrganisationInfoAfterRender
}
});
}
});
when I call ponent.add(generateField(n.customField.name));
I get "function not found" error
Super-stupid question, but I can't make it work, how do we call a function from another function within the same Controller
? I use sencha architect.
Here is my controller where I a have a listener and a function, I want to call generateField
function from the listener
Ext.define('Medlemssystem.controller.MemberOrganisationController', {
extend: 'Ext.app.Controller',
views: [
'LocalOrgPanel'
],
onLocalOrganisationInfoAfterRender: function(ponent, eOpts) {
main_id = ponent.up('#memberTab').main_id;
ponent.removeAll();
Ext.Ajax.request({
url: 'OrganizationCustomFieldServlet',
method: 'GET',
dataType: 'json',
params: {
"operation" : "get",
"org_id" : main_id
},
success: function(response) {
var result = Ext.decode(response.responseText);
result.forEach(function(n) {
ponent.add(generateField(n.customField.name));
});
},
failure: function() {
console.log('woops');
}
});
},
generateField: function(name, type, id, required, description) {
var field = Ext.create("Ext.form.field.Text", {fieldLabel:name});
return field;
},
init: function(application) {
this.control({
"LocalOrgPanel": {
afterrender: this.onLocalOrganisationInfoAfterRender
}
});
}
});
when I call ponent.add(generateField(n.customField.name));
I get "function not found" error
2 Answers
Reset to default 3After onLocalOrganisationInfoAfterRender: function(ponent, eOpts) {
paste var that = this;
And then ponent.add(that.generateField(n.customField.name));
An alternative way is to set scope for the ajax request call back.
Like this
Ext.Ajax.request({
url: 'OrganizationCustomFieldServlet',
method: 'GET',
dataType: 'json',
params: {
"operation" : "get",
"org_id" : main_id
},
success: function(response) {
console.log(this); //<-- scope here is Window by default, unless scope is set below
},
failure: function() {
console.log('woops');
},
scope :this //<-- Sets the controller as the scope for the success call back
});
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744906875a4600310.html
评论列表(0条)