gpt4 book ai didi

javascript - ExtJs 6 的全局函数

转载 作者:行者123 更新时间:2023-12-01 02:47:20 25 4
gpt4 key购买 nike

这是我的 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用于全局或通用功能。

Singleton 是一种只能有一个对象实例的类。在 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()
});

关于javascript - ExtJs 6 的全局函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47176251/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com