2017-11-08 4 views
0

hier ist meine Ajax-Funktionglobale Funktion für ExtJs 6

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

und meine meldung.php sieht wie folgt aus:

<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{ 
/// 
} 

} 

Wie kann ich einen funciton in ExtJs Code zu schreiben, die ich aus anrufen Klicken Sie hier auf Und ich habe keine Ahnung, wie es geht. Ich habe noch nichts probiert

Antwort

1

Wie schreibe ich eine Funktion in ExtJs Code, den ich von hier aus auf Click aufrufen kann und ich habe keine Ahnung, wie es geht. Ich habe noch nichts versucht

Ich denke, Sie können singleton für globale oder gemeinsame Funktionen verwenden.

Ein Singleton ist eine Klasse, die nur eine Objektinstanz haben kann. In ExtJS 4 oder höher Version wird ein Singleton-Objekt instanziiert, sobald die Anwendung geladen wird.

Ich habe eine kleine sencha fiddle Demo-Hoffnung erstellt, die Ihnen helfen wird.

//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() 
}); 
+0

OK, ich denke, das ist der einzige Weg, danke –

+0

NEIN, Sie können auch einen anderen Weg aufrufen. Ich verweise [Singleton] (https://docs.sencha.com/extjs/6.0.0/classic/Ext.Class.html), weil es Ihnen während Ihrer Anwendung hilft. Hier können Sie Ihre eigenen benötigten Variablen, Methoden und Formate definieren, was auch immer Sie hier tun möchten. Dies ist nützlich, wenn genau ein Objekt benötigt wird, um Aktionen im System zu koordinieren. –