ExtJS 4.1。
在Ext.button类上有类似Ext.button.click();
方法吗?
是否可以通过一种方法以编程方式“点击”按钮?
答案 0 :(得分:24)
或者如果你有MVC结构,你可以触发按钮的click事件,如果你正在控制器中监听事件并且有一个相关的功能,它将被调用。
button.fireEvent('click', button);
答案 1 :(得分:10)
此论坛上的最后一个答案可能会让您更深入地了解如何做到这一点 他们在这里 -
1)Create the event code in a function and call the function from both sides: btn.on("clic", ...) and from the code you want to simulate the click.
2)Use: btnView.btnEl.dom.click();
来自 - http://www.sencha.com/forum/showthread.php?37772-Solved-Programmatically-click-an-Ext.Button
答案 2 :(得分:6)
ExtJS 4.2.1
Ext.get('component-id-of-extjs-button').el.dom.click();
Ext.get('toggle-button2').el.dom.click();
适合我。
答案 3 :(得分:2)
如果按钮使用处理程序,您可以直接调用按钮的功能。
考虑button
是一个Ext JS组件,您可以使用:
button.handler(button);
或者如果您想要达到事件的功能,请点击':
button.listeners.click(button);
这也可以调用不同的按钮事件。
答案 4 :(得分:2)
由于我需要很多按钮,因此更容易在按钮类上实现覆盖,这会增加一个点击功能:
Ext.define('Ext.override.Button',{
override:'Ext.button.Button',
click:function() {
this.getEl().dom.click();
}
})
将此覆盖添加到代码库后,以下内容就像魅力一样:
Ext.getCmp("MyButton").click()
与fireEvent或fireHandler不同,它适用于所有类型的按钮 - 无论它们是否具有单击事件或处理程序,还是它们都是切换按钮,其中单击的按钮也必须被标记为按下。
答案 5 :(得分:1)
如果你需要执行按钮的“处理程序”,只需运行它(使用ExtJS 4.2测试)
button.fireHandler()
答案 6 :(得分:0)
如果您想在测试脚本中执行此操作,请查看我的Ext.ux.Test library。如果您需要其他东西,我建议您重新考虑您的方法。
答案 7 :(得分:0)
其他答案都没有对我有用,但我觉得我觉得有些简单:
var button=Ext.get('the_id_div');
button.dom.click();
答案 8 :(得分:0)
ionic serve
Running 'serve:before' npm script before serve
> TraduzindoSonhos@ watch C:\Users\Breno\Dropbox\Apps\TraduzindoSonhos\TraduzindoSonhos
> ionic-app-scripts watch
[09:15:23] ionic-app-scripts 0.0.36
[09:15:23] watch started ...
[09:15:23] build dev started ...
[09:15:23] clean started ...
[09:15:23] clean finished in 15 ms
[09:15:23] copy started ...
[09:15:24] transpile started ...
[09:15:24] lint started ...
[09:15:28] tslint: ...reno/Dropbox/Apps/TraduzindoSonhos/TraduzindoSonhos/src/services/bmbraga.http.ts,
line: 4
Unused import: 'Response'
L3: import { Injectable } from '@angular/core';
L4: import { Http, Response, Headers, RequestOptions } from '@angular/http';
L5: import {Observable} from 'rxjs/Rx';
[09:15:28] tslint: ...reno/Dropbox/Apps/TraduzindoSonhos/TraduzindoSonhos/src/services/bmbraga.http.ts,
line: 4
Unused import: 'Headers'
L3: import { Injectable } from '@angular/core';
L4: import { Http, Response, Headers, RequestOptions } from '@angular/http';
L5: import {Observable} from 'rxjs/Rx';
[09:15:28] tslint: ...reno/Dropbox/Apps/TraduzindoSonhos/TraduzindoSonhos/src/services/bmbraga.http.ts,
line: 4
Unused import: 'RequestOptions'
L3: import { Injectable } from '@angular/core';
L4: import { Http, Response, Headers, RequestOptions } from '@angular/http';
L5: import {Observable} from 'rxjs/Rx';
[09:15:28] tslint: ...reno/Dropbox/Apps/TraduzindoSonhos/TraduzindoSonhos/src/services/bmbraga.http.ts,
line: 5
Unused import: 'Observable'
L4: import { Http, Response, Headers, RequestOptions } from '@angular/http';
L5: import {Observable} from 'rxjs/Rx';
[09:15:28] tslint: ...ox/Apps/TraduzindoSonhos/TraduzindoSonhos/src/pages/item-details/item-details.ts,
line: 88
Unused variable: 'alert'
L87: console.log("login error: " + JSON.stringify(error));
L88: try {
L89: let alert = this.alertCtrl.create({
[09:15:28] tslint: ...sers/Breno/Dropbox/Apps/TraduzindoSonhos/TraduzindoSonhos/src/pages/home/home.ts,
line: 2
Unused import: 'NavParams'
L1: import { Component } from '@angular/core';
L2: import { NavController, NavParams, Platform } from 'ionic-angular';
L3: import { AlertController } from 'ionic-angular';
[09:15:28] tslint: ...sers/Breno/Dropbox/Apps/TraduzindoSonhos/TraduzindoSonhos/src/pages/home/home.ts,
line: 99
Unused variable: 'alert'
L98: try {
L99: let alert = this.alertCtrl.create({
L100: title: 'Server error',
[09:15:28] tslint: .../Apps/TraduzindoSonhos/TraduzindoSonhos/src/pages/letter-result/letter-result.ts,
line: 98
Unused variable: 'alert'
L97: try {
L98: let alert = this.alertCtrl.create({
L99: title: 'Server error',
[09:15:28] tslint: .../Apps/TraduzindoSonhos/TraduzindoSonhos/src/pages/search-result/search-result.ts,
line: 85
Unused variable: 'alert'
L84: try {
L85: let alert = this.alertCtrl.create({
L86: title: 'Server error',
[09:15:28] lint finished in 4.17 s
[09:15:30] typescript: ...rs/Breno/Dropbox/Apps/TraduzindoSonhos/TraduzindoSonhos/src/app/app.component.ts,
line: 37
Property 'analytics' does not exist on type 'Window'.
L36: try {
[09:15:30] typescript: ...sers/Breno/Dropbox/Apps/TraduzindoSonhos/TraduzindoSonhos/src/pages/home/home.ts, L37:
window. line: 27 a
nal[09:15:30] typescript: ...sers/Breno/Dropbox/Apps/TraduzindoSonhos/TraduzindoSonhos/src/pages/home/home.ts, y
t line: 34
i[09:15:30] typescript: ...sers/Breno/Dropbox/Apps/TraduzindoSonhos/TraduzindoSonhos/src/pages/home/home.ts, c
line: 68 s
.startTrackerWithId("UA-960473-35");
[09:15:30] typescript: ...ox/Apps/TraduzindoSonhos/TraduzindoSonhos/src/pages/item-details/item-details.ts, L38: }
catch line: 29 (e) {
Supplied parameters do not match any signature of call target.
[09:15:30] typescript: ...ox/Apps/TraduzindoSonhos/TraduzindoSonhos/src/pages/item-details/item-details.ts, L26:
this.block2Items = [];
line: 36 L27:
thi[09:15:30] typescript: ...ox/Apps/TraduzindoSonhos/TraduzindoSonhos/src/pages/item-details/item-details.ts, s
. line: 65 l
oadHomeItems([09:15:30] typescript: .../Apps/TraduzindoSonhos/TraduzindoSonhos/src/pages/letter-result/letter-result.ts,
);
line: 31 L28:
this.trackEvent();
Property 'analytics' does not exist on type 'Window'.
[09:15:30] typescript: .../Apps/TraduzindoSonhos/TraduzindoSonhos/src/pages/letter-result/letter-result.ts, L33:
try line: 38 {
L34: window.anal[09:15:30] typescript: .../Apps/TraduzindoSonhos/TraduzindoSonhos/src/pages/letter-result/letter-result.ts,
y line: 72 t
ics.trackEvent("Home");
L35: } catch (e) {
Cannot find name 'Response'.
L68: dataSuccess(res: Response) {
L69: this.loader.dismiss();
Supplied parameters do not match any signature of call target.
[09:15:30] typescript: .../Apps/TraduzindoSonhos/TraduzindoSonhos/src/pages/search-result/search-result.ts,
L28: line: 26 this.itemDetails = null;
L29: [09:15:30] typescript: .../Apps/TraduzindoSonhos/TraduzindoSonhos/src/pages/search-result/search-result.ts, t
h line: 33 i
[09:15:30] typescript: .../Apps/TraduzindoSonhos/TraduzindoSonhos/src/pages/search-result/search-result.ts, s
. line: 67 l
oadHomeItems();
L30: this.trackEvent();
Property 'analytics' does not exist on type 'Window'.
L35: [09:15:30] transpile failed
try {
L36: window.analytics.trackEvent("Details");
L37: } catch (e) {
Cannot find name 'Response'.
L65: dataSuccess(res: Response) {
L66: this.loader.dismiss();
Supplied parameters do not match any signature of call target.
L30: this.letter = this.letter.toUpperCase();
L31: this.loadHomeItems();
L32: this.trackEvent();
Property 'analytics' does not exist on type 'Window'.
L37: try {
L38: window.analytics.trackEvent("LSearch", "Letter", this.letter);
L39: } catch (e) {
Cannot find name 'Response'.
L72: dataSuccess(res: Response) {
L73: this.loadingItems = false;
Supplied parameters do not match any signature of call target.
L25: this.letter = navParams.get('search');
L26: this.loadHomeItems();
L27: this.trackEvent();
Property 'analytics' does not exist on type 'Window'.
L32: try {
L33: window.analytics.trackEvent("LSearch", "Letter", this.letter);
L34: } catch (e) {
Cannot find name 'Response'.
L67: dataSuccess(res: Response) {
L68: this.loader.dismiss();
[09:15:30] copy finished in 6.71 s
[09:15:30] watch ready in 6.79 s
Running live reload server: http://localhost:35729
Watching: www/**/*, !www/lib/**/*, !www/**/*.map
√ Running dev server: http://localhost:8100
Ionic server commands, enter:
restart or r to restart the client app from the root
goto or g and a url to have the app navigate to the given url
consolelogs or c to enable/disable console log output
serverlogs or s to enable/disable server log output
quit or q to shutdown the server and exit
ionic $ q