---
title: "Ext 2.02 API新增功能"
author: "sp42"
date: "2008-02-27T21:41:47Z"
tags: []
categories: ["Web前端"]
slug: "ext-2-02-api"
draft: false
lastmod: "2008-02-27T21:41:47Z"
id: 165579
url: "https://sp42.iteye.com/blog/165579"
---

为联合Adobe， [Ext2.02](http://extjs.com/download)当中重要的一项便是针对[AIR1.0](http://www.adobe.com/go/air)中应用程序的[沙箱(Application Suadbox)](http://labs.adobe.com/wiki/index.php/AIR:HTML_Security_FAQ#What_exactly_is_disabled_or_restricted_in_the_Application_sandbox.3F)提供运行的支持。另外，作为范本的AIR版的Simple Tasks（简易任务）已重写以体现AIR原生功能还有一部分Ext制定组件是可以在AIR之外使用。

### AIR APIs

首先，一些会用到的API我们先讲讲:

**原生Window NativeWindow**

Ext.air包其中一项最有用的功能。此API可创建、管理Windows，例如侦听事件发挥了标准的Ext观察者和Windows自动状态管理的作用。

 

```
var win = new Ext.air.NativeWindow({     id: winId,     file: 'task.html',     width:500,     height:350,     resizable: true });
```

![](http://extjs.com/playpen/screenshots/air/task-window.png)

Task NativeWindow in Simple Tasks 2

**Ext.sql.\***

在AIR早期的beta版本中，数据库访问的方式为异步访问。随着beta3中可使用同步方式访问，Ext.data.Record亦相应提供升级的支持。

Simple Tasks演示了怎么在SQLite数据库中持久Ext.data.Record的实例，整合的过程并不困难。

 

```
tx.data.ListStore = Ext.extend(Ext.data.Store, {     constructor: function(){         // superclass call         tx.data.ListStore.superclass.constructor.call(this, {             sortInfo:{field: 'listName', direction: "ASC"},             reader: new Ext.data.JsonReader({                 id: 'listId',                 fields: tx.data.List             })         });           this.conn = tx.data.conn;         // Ext.sql.Proxy for managing Sqlite persistence         this.proxy = new Ext.sql.Proxy(tx.data.conn, 'list', 'listId', this);     },     ...
```

 

**原生的拖放和剪贴板**  
Simple Tasks支持拖动任意的文本拖动到Grid，自动转回为新任务（Task）。而且也可以从的系统的剪贴板粘贴新建任务，不过，其中一项最COOL的功能就是允许直接从OUTLOOK拖动任务到SimpleTask。

![](http://extjs.com/playpen/screenshots/air/outlook.png)

Dragging Outlook tasks into Simple Tasks

**最小化系统状态功能**

第一版的SimpleTask发布后，ExtJS内部这里需求最大的就是最小化window系统状态栏的功能。我们将自动控制系统托盘（System Tray）的功能加入到Ext.air.NativeWindow这个类中。这样，通过设置一下配置项就可最小化到系统托盘。

 

```
var win = new Ext.air.NativeWindow({     id: 'mainWindow',     instance: window.nativeWindow,       // System tray config     minimizeToTray: true,     trayIcon: 'ext-air/resources/icons/extlogo16.png',     trayTip: 'Simple Tasks',     trayMenu : [{         text: 'Open Simple Tasks',         handler: function(){             win.activate();         }     }, '-', {         text: 'Exit',         handler: function(){             air.NativeApplication.nativeApplication.exit();         }     }] });
```

![](http://extjs.com/playpen/screenshots/air/system-tray.png)

Simple Tasks in the System Tray

**音效**  
AIR支持播放音效，Ext.air.Sound的用法甚至更简单了。

 

```
Ext.air.Sound.play('beep.mp3');
```

![](http://extjs.com/playpen/screenshots/air/reminder.png)

The irritating beeping sound is sure to catch your attention

### Ext制定的组件

如上文述，整个SimpleTask的程序包含了几个示范的EXT自定义组件。其中一部分是为了复用而专门设计的，未来发布的版本或许会成为标准的组件或示例。

 

**ListTree**  
    ListTree与 ComboBox或SelectBox相类似，不同在于出现的是一块Ext TreePanel面板。比起普通的垂直列表更能清晰显示各层次的列表。  
    伴随着这个组件另外一个酷的功能是制定的选区模型“ActivationModel”。顾名思义，它以两种形式出现（activation活动选区和记录选区selection），在活动选区下，组件支持完整的键盘控制、用键盘展开/闭合， 与标准树选区模型不同，此选区属于动作本身。

![](http://extjs.com/playpen/screenshots/air/treelist.png)

TreeList supports selection of data organized hierarchically

**自定义Gird列**  
截屏图片可第一时间解释清楚。

![](http://extjs.com/playpen/screenshots/air/column1.png)

Pseudo button column, used to toggle complete/active

![](http://extjs.com/playpen/screenshots/air/column2.png)

Menu column, used to set quick reminders

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Siwthc按钮

有一种类似radio按钮（单选按钮）的组件好像在桌面的应用程序上经常看得到。这儿就叫作“Switch”按钮，以便不会与标准HTML的radio按钮出现混淆。它的作用是：提供一组的按钮，同时“被按下”的只能是一个。

![](http://extjs.com/playpen/screenshots/air/switch.png)

Quick view change

**总结**

无论是AIR本身的功能还是EXT的扩展，这些都可以在Simple Tasks v2的程序源码中找到真正应用的地方。如果你正在使用着Ext，那么我推荐浏览这些源码。  
    －完整的源码可以在Ext 2.02的[发布版本](http://extjs.com/download)中的air/samples/tasks找到。  
    －Adobe AIR 1.0 [下载](http://get.adobe.com/air/)  
    －Simple Tasks v2 面向AIR的版本 [下载](http://extjs.com/playpen/STasks2.air)  
    －有关Simple Tasks首个版本可查阅[上次的博文](http://extjs.com/blog/2007/06/29/building-a-desktop-application-with-ext-air-aptana-and-red-bull/)。

 

作者：Jack Slocum