从Sencha Touch Class调用常规JS函数

时间:2013-01-23 17:43:55

标签: javascript facebook facebook-graph-api extjs sencha-touch

有人可以解释我怎么做到这一点?我试图获取FB访问令牌并将其附加到商店配置中的URL字符串。就这样......

Ext.define('clubs.store.FacebookEvent', {
extend: 'Ext.data.Store',
requires: [
    'clubs.model.FacebookEvent'
],

config: {
    autoLoad: true,
    model: 'clubs.model.FacebookEvent',
    //storeId: 'FacebookEventStore',
    proxy: {
        type: 'jsonp',
        url: 'https://graph.facebook.com/474381199275383/?fields=description,name&access_token=' + getAccessCode(),

        reader: {
            type: 'json'
            //rootProperty: 'data'
        }
    }
}

});

function getAccessCode(){
FB.getLoginStatus(function(response) {
    if (response.status === 'connected') {
        var uid = response.authResponse.userID;
        var accessToken = response.authResponse.accessToken;
        console.log(accessToken);
    }
});
return accessToken;

}

但是我似乎总是在我的JS控制台中出现这个错误......

uncaught Error: The following classes are not declared even if their files have been loaded: 'club.store.FacebookEvent'. Please check the source code of their corresponding files for possible typos:

我是以错误的方式来做这件事的吗?任何帮助将非常感激!

2 个答案:

答案 0 :(得分:1)

理想情况下,您应该将它放在控制器或任何单例实用程序类中,然后像这样访问它:

this.getApplication().getController('ControllerName').getAccessCode()

OR

UtilsClass.getAccessCode()

但是如果你想保留它,你必须定义这样的函数:

config : {
    //..blah blah
},
getAccessCode : function(){
  FB.getLoginStatus(function(response) {
    if (response.status === 'connected') {
    var uid = response.authResponse.userID;
    var accessToken = response.authResponse.accessToken;
    console.log(accessToken);
    }
  });
  return accessToken;
}

答案 1 :(得分:0)

您只需要从

更改类定义
Ext.define('clubs.store.FacebookEvent',

Ext.define('club.store.FacebookEvent',

事实上,您的应用名称是分会,而不是分会