文档帮助

术语、图标和标签

许多类在使用配置对象创建(实例化)类时都有快捷名称。快捷名称被称为 别名(如果类扩展了 Ext.Component,则为 xtype)。别名/xtype 列在适用类的类名旁边,以便快速参考。

访问级别

框架类或其成员可以指定为 privateprotected。否则,该类/成员为 publicPublicprotectedprivate 是访问描述符,用于传达类或类成员应如何以及何时使用。

成员类型

成员语法

下面是一个类成员示例,我们可以对其进行剖析,以显示类成员的语法(在本例中为从 Ext.button.Button 类查看的 lookupComponent 方法)。

lookupComponent ( item ) : Ext.Component
protected

当原始配置对象添加到此容器时调用,无论是在初始化 items 配置期间,还是在 added) 或 {@link #insert inserted 新项时。

此方法将传递的对象转换为实例化的子组件。

当需要对子组件创建应用特殊处理时,可以在子类中覆盖此方法。

参数

item :  Object

正在添加的配置对象。

返回值
Ext.Component

要添加的组件。

让我们看一下成员行的每个部分

成员标志

API 文档使用许多标志来进一步传达类成员的功能和意图。标签可以用文本标签、缩写或图标表示。

类图标

- 表示框架类

- 单例框架类。 *有关更多信息,请参阅单例标志

- 组件类型框架类(Ext JS 框架中扩展 Ext.Component 的任何类)

- 表示类、成员或指南在当前查看的版本中是新的

成员图标

- 表示 config 类型的类成员

- 表示 property 类型的类成员

- 表示 method 类型的类成员

- 表示 event 类型的类成员

- 表示 theme variable 类型的类成员

- 表示 theme mixin 类型的类成员

- 表示类、成员或指南在当前查看的版本中是新的

类成员快速导航菜单

在 API 文档页面上的类名正下方是一行按钮,对应于当前类拥有的成员类型。每个按钮显示按类型划分的成员计数(此计数会随着应用过滤器而更新)。单击按钮将导航到该成员部分。将鼠标悬停在成员类型按钮上将显示该类型的所有成员的弹出菜单,以便快速导航。

Getter 和 Setter 方法

与类配置选项相关的 Getter 和 setter 方法将在方法部分以及 API 文档和成员类型菜单的 configs 部分中显示,紧挨着它们所适用的配置下方。getter 和 setter 方法文档将在配置行中找到,以便于参考。

历史记录栏

您的页面历史记录保存在本地存储中,并显示在顶部标题栏正下方(使用可用的实际空间)。默认情况下,仅显示的搜索结果是与您当前查看的产品/版本匹配的页面。您可以通过单击历史记录栏右侧的 按钮并选择“全部”单选按钮来扩展显示的内容。这将显示所有产品/版本的所有最近页面历史记录栏。

在历史记录配置菜单中,您还将看到最近访问页面的列表。结果按“当前产品/版本”和“全部”单选按钮过滤。单击 按钮将清除历史记录栏以及本地存储中保存的历史记录。

如果在历史记录配置菜单中选择“全部”,则将启用“在历史记录栏中显示产品详细信息”复选框选项。选中后,每个历史页面的产品/版本将与页面名称一起显示在历史记录栏中。将光标悬停在历史记录栏中的页面名称上也会将产品/版本显示为工具提示。

搜索和过滤器

可以使用页面顶部的搜索字段搜索 API 文档和指南。

在 API 文档页面上,还有一个过滤器输入字段,该字段使用过滤器字符串过滤成员行。除了按字符串过滤外,您还可以按访问级别、继承和只读来过滤类成员。这是通过使用页面顶部的复选框完成的。

API 类导航树底部的复选框过滤类列表以包含或排除私有类。

单击空的搜索字段将显示您最近的 10 次搜索,以便快速导航。

API 文档类元数据

每个 API 文档页面(JavaScript 原始类型页面除外)都有一个与该类相关的元数据菜单视图。此元数据视图将具有以下一个或多个

展开和折叠示例以及类成员

可运行的示例 (Fiddles) 默认在页面上展开。您可以使用代码块左上角的箭头单独折叠和展开示例代码块。您还可以使用页面右上角的切换按钮切换所有示例的折叠状态。所有切换状态将在页面加载之间记住。

类成员默认在页面上折叠。您可以使用成员行左侧的箭头图标或全局使用右上角的展开/折叠所有切换按钮来展开和折叠成员。

桌面视图与移动视图

在较窄的屏幕或浏览器上查看文档将导致针对较小外形尺寸优化的视图。桌面视图和“移动”视图之间的主要区别在于

查看类源代码

可以通过单击 API 文档页面顶部的类名来查看类源代码。可以通过单击成员行右侧的“查看源代码”链接来查看类成员的源代码。

GXT 4.x


顶部

GWT 和 Java 基础知识

与 Java 和 GWT 一起使用的基本结构和函数。

变量

创建 & 赋值

  • 使用 Java 和 GWT

      // Explicit type
      String name = "Brandon";
    
      // Non typed variable
      Object name = "Brandon";
    

默认值

  • 使用 Java 和 GWT

      String name; // is null
      int y; // is 0
    

Final 变量

  • 使用 Java 和 GWT

      public final class Bird {
        public final String name = "Tweety";
        public Bird() {
          this.name = "can't reassign"; // can't do on finals
        }
      }
    

集合

数组 & 列表

  • 使用 Java 和 GWT

      int[] a = new int[5];
      String[] ns = { "0", "1", "2", "3", "4" };
    
      int size = ns.length;
    
      // Generics
      List<Integer> a = Arrays.asList(new Integer[]{1, 2});
      List<String> d = new ArrayList<String>();
    

自定义排序

  • 使用 Java 和 GWT

      List<Double> numbers = new ArrayList<Double>();
      numbers.add(42D);
      numbers.add(2.1);
      numbers.add(5D);
      numbers.add(0.1);
      numbers.add(391D);
    
      Collections.sort(numbers);    
    
      // Or a manual sort
      Collections.sort(numbers, new Comparator<Double>() {
        @Override
        public int compare(Double a, Double b) {
          return a.compareTo(b);
        }
      });
    
      System.out.println(numbers); // is [0.1, 2.1, 5.0, 42.0, 391.0]
    

键值对

  • 使用 Java 和 GWT

      Map<String, String> periodic = new HashMap<String, String>();
    

使用键

  • 使用 Java 和 GWT

      Map<String, String> peeps = new HashMap<String, String>();
      peeps.put("Fred", "tall");
      peeps.put("Joe", "short");
    
      // Child object uses methods equals(Object) and hashCode()
      Map<Child, String> favorites = new HashMap<Child, String>();
      favorites.put(new Child("Sam"), "Ball");
    

集合 (Set)

唯一集合。

  • 使用 Java 和 GWT

      Set<String> items = new HashSet<String>();
      items.add("one");
      items.add("two");
      items.size(); // has 2
    
      items.add("three");
      items.size(); // has 3
    

队列 (FIFO)

  • 使用 Java 和 GWT

      Queue<String> queue = new LinkedList<String>();
      queue.add("evt:1111");
      queue.add("evt:2222");
    
      System.out.println(queue.size());  // has 2
    
      String eventId = queue.remove();
    
      System.out.println(eventId == "evt:1111"); // is true
      System.out.println(queue.size()); // has 1
    

字符串

原始字符串

  • 使用 Java 和 GWT

      char[] raw = { 'G', 'X', 'T', ' ', '.', '.', '.', ' ', '\\', 't' };
    
      String string = "GXT ... \\t";
    

插值

  • 仅使用 Java

      String name = "Brandon";
      String hello = String.format("I'm %s.", name);
    
      String helloFormatted = String.format("But you can call me, %sski.", name);
    
      int top = 13;
      String property = String.format("%spx", (top + 15));    
    

连接

  • 使用 Java 和 GWT

      String message = "One line. "
                     + "Two line.";
    

子字符串

  • 使用 Java 和 GWT

      "redhouses".substring(3, 8) // is 'house'
    

替换所有出现项

  • 使用 Java 和 GWT

      "doghouses".replaceAll("s", "z") // is 'doghouzez'
    

替换一个出现项

  • 使用 Java 和 GWT

      "fastcar".replaceFirst("fast", "space") // is 'spacecar'
    

多行字符串

  • 使用 Java 和 GWT

      String string = "";
      string += "One line. ";
      string += "Two lines.";
    

拆分为数组

  • 使用 Java 和 GWT

      String alpha = "a, b, c, d";
      String[] group = alpha.split(", "); // is ["a", "b", "c", "d"];
    

子字符串测试

  • 使用 Java 和 GWT

      "fastcar".startsWith("fast"); // is true
      "lowrider".startsWith("cool"); // is false
    

布尔值

If 语句

  • 使用 Java 和 GWT

      int[] numbers = {1, 2, 3, 4};
      if (numbers.length > 2) {
        System.out.println("do something");
      }        
    

三元运算符

  • 使用 Java 和 GWT

      int[] numbers = new int[] { 1, 2, 3, 4 };
      String condition = numbers.length > 2 ? "Good" : "Bad";
      System.out.println("The condition is " + condition);        
    

空字符串

  • 使用 Java 和 GWT

      String empty = "";
      if (empty.isEmpty()) {
          System.out.println("empty");
      }        
    

  • 使用 Java 和 GWT

      int zero = 0;
      if (zero == 0) {
        System.out.println("zero");
      }
    
      Integer zero2 = 0;
      if (zero2.equals(0)) {
        System.out.println("zero");
      }
    

Null

  • 使用 Java 和 GWT

      String myNull = null;
      if (myNull == null) {
        System.out.println("is null");
      }
    

NAN

  • 使用 Java 和 GWT

      Double nan = Double.NaN;
      if (Double.isNaN(nan)) {
          System.out.println("NaN");
      }
    

相等性

  • 使用 Java 和 GWT

          String letterA = "A";
          char charA = 65;
    
          letterA == charA // is false
          letterA.equals(String.valueOf(charA)) // is true
    
          int number5 = 5;
          String char5 = "5";
    
          number5 == char5 // incompatible type comparision
          Integer.toString(number5).equals(char5) // is true
    
          class User {
            String name;
            String ssn;
    
            User(String name, String ssn) {
              this.name = name;
              this.ssn = ssn;
            }
    
            @Override
            public boolean equals(Object obj) {
              User p = (User) obj;
              return ssn.equals(p.ssn);
            }
    
            @Override
            public int hashCode() {
              final int prime = 31;
              int result = 1;
              result = prime * result + ((name == null) ? 0 : name.hashCode());
              return result;
            }
          }
    
          new User("Brandon", "111").equals(new User("Robert", "111") // is true        
    

函数

函数定义

  • Java 和 GWT

      // Java uses methods intead of functions like Javascript and Dart
      boolean method() {
        // ...
        return true;
      }
    
      void method2() {
        // ...
      }        
    

返回值

  • Java 和 GWT

      boolean isMethod() {
        return true;
      }
    
      TheType getTheTypeMethod() {
        return new TheType();
      }
    
      void method() {
        // returns nothing
      }
    

将函数赋值给变量

  • Java 1.8

      public class LambdaExample {
        interface Loudify {
          String loudify(String msg);
        }
    
        public static void main(String[] args) {
          Loudify loudify = (String msg) -> msg.toUpperCase();
    
          System.out.println(loudify.loudify("not gonna take it anymore"));
        }
      }        
    

可变数量的参数或 VarArgs

  • Java 和 GWT

      public void method(String... strings) {
      }
      method("a", "b", "c");
    

迭代器

列表的 For 循环

  • Java 和 GWT

      List<String> letters = new ArrayList<String>();
      letters.add("a");
      letters.add("b");
      letters.add("c");
    
      for (int i = 0; i < letters.size(); i++) {
        System.out.println(letters.get(0));
      }
    

For-in 循环

  • Java 和 GWT

      List<String> letters = new ArrayList<String>();
      letters.add("a");
      letters.add("b");
      letters.add("c");
    
      for (String letter : letters) {
        System.out.println(letter);
      }
    

对象/映射的 For 循环

  • Java 和 GWT

      Map<String, String> letters = new HashMap<String, String>();
      letters.put("1", "a");
      letters.put("2", "b");
      letters.put("3", "c");
    
      for (String key : letters.keySet()) {
        System.out.println(key + ", " + letters.get(key));
      }
    
      Set<String> letters2 = new HashSet<String>();
      letters2.add("e");
      letters2.add("f");
      letters2.add("g");
    
      Iterator<String> iterator = letters2.iterator();
      while (iterator.hasNext()) {
        System.out.println(iterator.next());
      }
    

循环中带有计数器的闭包

  • Java 1.8

      public class LambdaExample {
        public interface Callback {
          void callback();
        }
    
        public static void main(String[] args) {
          List<Callback> callbacks = new ArrayList<Callback>();
    
          for (int i = 0; i < 2; i++) {
            final int ii = i;
            Callback callback = () -> System.out.println(Integer.toString(ii));
            callbacks.add(callback);
          }
    
          callbacks.get(0).callback(); // is 0
          callbacks.get(1).callback(); // is 1
        }
      }
    

结构

  • Java 和 GWT

      public class User {
        private String name;
    
        public String greet() {
          return String.format("Hello, %s", name);
        }
      }
    

带参数的构造函数

  • Java 和 GWT

      public class User {
        private String name;
    
        public User(String name) {
          this.name = name;
        }
      }
    

实例化

  • Java 和 GWT

      User User = new User();
    

反射

  • Java 和 GWT

      User User = new User("a");
      System.out.println(User.getClass().getSimpleName()); // is User
    

类型比较

  • Java 和 GWT

      String name = "Brandon";
      System.out.println(name instanceof String); // is true
    

子类

  • Java 和 GWT

      public class User {
        private String name;
    
        public User(String name) {
          this.name = name;
        }
    
        public String greet() {
          return "Hello, " + name;
        }
      }
    
      public class Info extends User {
        private int salary;
    
        public Info(String name, int salary) {
          super(name);
          this.salary = salary;
        }
    
        public void raisePay(double percent) {
          percent /= 100;
          salary += (salary * percent);
        }
    
        public int getSalary() {
          return salary;
        }
      }
    

定义库

  • 使用 Java 和 GWT

      // Package namespace declaration
      package animals;
    
      // One class per file
      public class Dog {
        public String bark() {
          return "woof!";
        }
      }
    

使用库

  • 使用 Java 和 GWT

      // Prepending package to class instantiation
      Dog woofy = new animals.Dog();
    
      // Package import declaration
      import animals;
      Dog woofy = new Dog();
    

数学

绝对值

  • Java 和 GWT

      Math.abs(-7) // is 7
    

向上取整

  • Java 和 GWT

      Math.ceil(7.78); // is 7.0
    

向下取整

  • Java 和 GWT

      Math.floor(3.89); // is 3.0
    

随机数

  • Java 和 GWT

      Random rand = new Random();
      rand.nextDouble();
      rand.nextBoolean();
      rand.nextInt();
    

正弦和余弦

  • Java 和 GWT

      Math.sin(Math.PI / 2); // is 1.0
      Math.cos(Math.PI); // is -1.0
    

将字符串转换为数字

  • Java 和 GWT

      Integer.parseInt("2") // is 2
      Double.parseDouble("4.18") // is 4.18
    
      Integer.parseInt("2px") // is ERROR
      Integer.parseInt("two") // is ERROR
    

GXT 4.x