【问题标题】:How to create a function in Sencha Architect?如何在 Sencha Architect 中创建函数?
【发布时间】:2012-05-11 06:09:36
【问题描述】:
Ext.Ajax.request({
   url: 'foo.php',    // where you wanna post
   success: passFn,   // function called on success
   failure: failFn,
   params: { foo: 'bar' }  // your json data
});

我正在关注How to post json data with extJS 并收到有关功能的问题。我看到我们可以在 passFn 和 failFn 区域中嵌入函数。但是,如果我希望这些功能在别处怎么办?在 Sencha Architect 中哪里可以创建这些函数并对其进行编码?

【问题讨论】:

    标签: function extjs sencha-architect


    【解决方案1】:

    以下是在架构师中使用基本功能的方法:

    1. 创建一个控制器。

    2. 添加一个控制器动作并设置它的属性如下:

      controlQuery: '#btn1', // (a button component with id "btn1")
      targetType  : Ext.Button, // (component type)
      fn          : onBtn1Tap, // (function name)
      name        : tap // (event)
      
    3. 添加一个基本函数并设置它的属性:

      fn: basicFunction  (function name)
      
    4. 现在你可以在 onBtn1Tap 中使用这个基本功能了:this.basicFunction()

    【讨论】:

      【解决方案2】:

      您可以创建一个不受 Sencha Architect 控制的文件夹,并从您的 Architect 代码中调用它。

      例如,我喜欢创建一个名为“util”的文件夹。因此,您的文件夹结构如下所示:

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

      在 MiscFunctions.js 中,您可以像这样创建类:

      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
      

      part,否则您将不得不创建该类的实例才能使用其中的函数。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多