鍍金池/ 教程/ HTML/ Meteor Assets資源
Meteor結(jié)構(gòu)
Meteor部署
Meteor排序
Meteor事件
Meteor Blaze
Meteor第一個(gè)應(yīng)用程序
Meteor發(fā)布和訂閱
Meteor環(huán)境安裝配置
Meteor package.js
Meteor在手機(jī)上運(yùn)行
Meteor集合
Meteor模板
Meteor跟蹤器
Meteor發(fā)送郵件
Meteor計(jì)時(shí)器
Meteor ToDo App實(shí)例
Meteor軟件包管理
Meteor方法
Meteor表單
Meteor Assets資源
Meteor會(huì)話
Meteor EJSON
Meteor http
Meteor安全
Meteor核心API
Meteor check
Meteor帳號(hào)
Meteor教程

Meteor Assets資源

靜態(tài)服務(wù)器資源位于應(yīng)用程序內(nèi)的 private 子文件夾。在這個(gè)例子中,我們將學(xué)習(xí)如何從簡(jiǎn)單的JSON文件中使用數(shù)據(jù)。

第1步 - 創(chuàng)建文件和文件夾

讓我們創(chuàng)建一個(gè) private 文件夾并在這個(gè)文件內(nèi)創(chuàng)建 my-json.json 文件。我們將從命令提示符窗口來(lái)創(chuàng)建目錄,但您可以手動(dòng)創(chuàng)建它。

C:\Users\Administrator\Desktop\meteorApp>mkdir private
C:\Users\Administrator\Desktop\meteorApp\private>touch my-json.json

步驟2A - 獲取文本

為了能夠從文件中讀取數(shù)據(jù),使用Assets.getText方法。要記住重要的是,這只能在服務(wù)器端來(lái)完成。由于我們使用JSON,需要分析它。

if (Meteor.isServer) {
   var myFile = JSON.parse(Assets.getText('my-json.json'));
   console.log(myFile.data.text)
}
我們可以看到,在命令提示符窗口中顯示輸出。

Meteor Assets Get Text

步驟1B - 創(chuàng)建JSON文件

我們將在 private 文件夾內(nèi)創(chuàng)建此文件。此文件將包含二進(jìn)制數(shù)據(jù) "myBinary": {"$binary": "c3VyZS4="}

C:\Users\Administrator\Desktop\meteorApp\private>touch my-ejson.ejson

步驟2B - 獲取二進(jìn)制

要讀取JSON文件,我們可以使用Assets.getBinary方法。
if (Meteor.isServer) {
   var myFile = Assets.getBinary('my-ejson.ejson');
   console.log(EJSON.stringify(myFile));
}
命令提示符將記錄EJSON值。

Meteor Assets Get Binary

上一篇:Meteor會(huì)話下一篇:Meteor check