- Meteor 教程
- Meteor - 主頁
- Meteor - 概述
- Meteor - 環境設定
- Meteor - 首次應用
- Meteor - 模板
- Meteor - 集合
- Meteor - 表單
- Meteor - 事件
- Meteor - 會話
- Meteor - 跟蹤器
- Meteor - 包
- Meteor - 核心 API
- Meteor - 檢查
- Meteor - 烈焰
- Meteor - 定時器
- Meteor - EJSON
- Meteor - HTTP
- Meteor - 電子郵件
- Meteor - 資產
- Meteor - 安全
- Meteor - 排序
- Meteor - 帳號
- Meteor - 方法
- Meteor - Package.js
- Meteor - 釋出與訂閱
- Meteor - 結構
- Meteor - 部署
- Meteor - 移動版執行
- Meteor - 待辦事項應用
- Meteor - 最佳做法
- 有用的 Meteor 資源
- Meteor - 快速指南
- 有用的 Meteor 資源
- Meteor - 討論
Meteor - 核心 API
如果你希望僅在伺服器或客戶端執行程式碼,可以使用以下程式碼:
meteorApp.js
if (Meteor.isClient) {
// Code running on client...
}
if (Meteor.isServer) {
// Code running on server...
}
當應用使用 Cordova 捆綁時,你僅可將程式碼限制執行。
if (Meteor.isCordova) {
// Code running on Cordova...
}
部分外掛需要等到伺服器和 DOM 已準備就緒。可使用以下程式碼等到所有事物開始。
Meteor.startup(function () {
// Code running after platform is ready...
});
下列表格列出了其他部分核心 API 方法。
| 序號 | 方法與詳細資訊 |
|---|---|
| 1 | Meteor.wrapAsync(function) 用於包裝非同步程式碼並將其轉換為同步。 |
| 2 | Meteor.absoluteUrl([path], [options]) 用於生成指向應用的絕對 URL。 |
| 3 | Meteor.settings 用於設定部署配置。 |
| 4 | Meteor.publish(name, function) 用於向客戶端釋出記錄。 |
廣告