嗨,我正在尝试在 Cordova 应用程序中使用 torii。我的 environment.js 文件如下所示。我无法访问窗口文档对象来设置redirectUri。获取错误 undefined variable 。如何访问窗口文档对象。
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
}
所以我认为文档应该是全局可用的,但它不是
最佳答案
您可以访问 window
和 document
对象通过你的大部分 Ember.js 代码作为全局变量。
在此特定文件中,您尝试访问它以用于应用程序配置。问题在于配置是在 Node.js 构建过程中生成的——这意味着上下文不一样。
您将在应用程序的页面源中看到配置是静态的并序列化为页面中的元属性:
<meta name="[your-app]/config/environment" content="your-config-here" />
由于重定向 url 将根据用户的位置动态更改,因此为 OAuth 流“及时”提取此数据会更容易。
关于ember.js - 在 ember-cli 环境中访问窗口对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25609303/