ExtJs 6 的全局函数

Global function for ExtJs 6

这是我的 Ajax 函数

 Ext.Ajax.request({
        url : 'report.php',
        method: 'POST',
        success: function (result, request ) {
            panel.update(result.responseText);
            mask.hide();
        }
    });

我的 report.php 看起来像这样:

<tr>
<td class='center'><b>Company</b></td>
    <td class='center'><b>User</b></td>
    <td class='center'><b>Report</b></td>
</tr>
<tr>
<?php foreach ($data as $day) {?>
  if($day == $today){
<td onClick="ExtJsFunction()"><?php $today?></td>
}else{
///
}

}

我如何在 ExtJs 代码中编写一个函数,我可以在点击时从这里调用 我不知道该怎么做。我还没有尝试过任何东西

How do i write a funciton in ExtJs code that i can call from here on click And i have no idea how to do it. I haven't tried anything yet

我认为您可以将 singleton 用于全局或通用函数。

A Singleton 是一个只能有一个对象实例的 class。在 ExtJS 4 或更高版本中,一旦加载应用程序,就会实例化一个单例对象。

我创建了一个小 sencha fiddle 演示,希望这对您有所帮助。

//singleton here is {singleton} class
Ext.define('Gloabal', {
    singleton: true,
    alternateClassName: 'globalUtilities',
    doApiCall: function (el) {
        Ext.Msg.alert('Succes','You have clicked on <b>'+el.innerText);
        //you can call your api here...
        //on basis of your requirment
    }
});

Ext.create('Ext.form.Panel', {
    title: 'Simple Form',
    bodyPadding: 5,
    width: 350,

    // The form will submit an AJAX request to this URL when submitted
    url: 'save-form.php',

    // Fields will be arranged vertically, stretched to full width
    layout: 'anchor',
    defaults: {
        anchor: '100%'
    },

    // The fields
    defaultType: 'textfield',
    items: [{
        fieldLabel: 'First Name',
        name: 'first',
        allowBlank: false
    }, {
        fieldLabel: 'Last Name',
        name: 'last',
        allowBlank: false
    }, {
        xtype: 'label',
        html: '<table style="width: 100%;border-collapse: collapse;text-align: center;cursor: pointer;"><tr>' +
            '<td onclick=globalUtilities.doApiCall(this) style="border:1px solid #ccc;">API 1</td>' +
            '<td onclick=globalUtilities.doApiCall(this) style="border:1px solid #ccc;">API 2</td>' +
            '<td onclick=globalUtilities.doApiCall(this)  style="border:1px solid #ccc;">API 3</td>' +
            '</tr></table>'
    }],

    // Reset and Submit buttons
    buttons: [{
        text: 'Reset',
        handler: function () {
            this.up('form').getForm().reset();
        }
    }],
    renderTo: Ext.getBody()
});