How to create a function in Sencha Architect?

Ext.Ajax.request({
   url: 'foo.php',    // where you wanna post
   success: passFn,   // function called on success
   failure: failFn,
   params: { foo: 'bar' }  // your json data
});

I follow How to send json data using extJS and got a question about functions. I see that we can embed functions directly in the passFn and failFn scope. However, if I want these functions to be elsewhere? Where to create these functions and encode them in Sencha Architect?

+3
source share
2 answers

You can create a folder outside the Sencha Architect control and call it from within the Architect code.

For example, I like to create a folder called "util". So, here is what your folder structure will look like:

app
  -- controller
  -- model
  -- store
  -- view
  -- util    <--- I added this directory
      -- MiscFunctions.js  <-- your own class file

Inside MiscFunctions.js, you must create a class as follows:

Ext.define('MyApp.util.MiscFunctions', {
   singleton: true,
   passFn: function() {
      ...
   },
   failFn: function() {
   }
});

Architect:

Ext.Ajax.request({
   url: 'foo.php',    // where you wanna post
   success: MyApp.util.MiscFunctions.passFn,   // function called on success
   failure: MyApp.util.MiscFunctions.failFn,
   params: { foo: 'bar' }  // your json data
});

singleton: true

.

+4

:

  • .

  • :

    controlQuery: '#btn1', // (a button component with id "btn1")
    targetType  : Ext.Button, // (component type)
    fn          : onBtn1Tap, // (function name)
    name        : tap // (event)
    
  • :

    fn: basicFunction  (function name)
    
  • onBtn1Tap: this.basicFunction()

+1

All Articles