2014-09-01 50 views
4

嗨我試圖在cordova應用程序中使用torii。我的environment.js文件如下所示。我無法訪問窗口文檔對象來設置redirectUri。獲取錯誤未定義的變量。我怎樣才能訪問窗口文檔對象。在炭燼環境中訪問窗口對象

module.exports = function (environment) { 
    var ENV = { 
     environment: environment, 
     baseURL: '/', 
     locationType: 'hash', 
     EmberENV: { 
      FEATURES: { 
       // Here you can enable experimental features on an ember canary build 
       // e.g. 'with-controller': true 
      } 
     }, 
     APP: { 
      // Here you can pass flags/options to your application instance 
      // when it is created 
     }, 
     torii: { 
      providers: { 
       'facebook-oauth2': { 
        apiKey: '2xxxxxxxxxx', 
        redirectUri: document.location.href 
       }, 
      } 
     }, 
     cordova: { 
      rebuildOnChange: false, 
      rebuildAsync: false, 
      emulate: false 
     } 
    }; 

在我.jshintrc

"predef": { 
    "document": true, 
    "window": true, 
    "AuthENV": true 
    } 

所以我假設文件應該是全球可用的,但它不是

+0

你如何使用'window'和'document'對象 - 你能提供一個樣本嗎? – bonesbrigade 2015-09-19 23:26:22

+0

redirectUri:document.location.href // here – Rigel 2015-09-20 03:37:54

回答

1

您可以通過大部分的餘燼訪問windowdocument對象。 js代碼作爲全局變量。

在這個特定的文件中,您試圖訪問它用於應用程序配置。問題是配置是在Node.js構建過程中生成的 - 這意味着上下文不一樣。

你會在你的應用程序的網頁的源文件,該配置是靜態的,序列化到頁面元屬性看到:

<meta name="[your-app]/config/environment" content="your-config-here" /> 

由於重定向URL會動態變化,這取決於用戶的位置,它將會更容易地爲OAuth流「準時」提供這些數據。