我正在开发简单的 Flux+Reactjs 应用程序,在我的商店中我有:
var ProfileStore = merge(EventEmitter.prototype, {
/**
* Get the entire collection of Profiles.
* @return {object}
*/
getAll: function() {
//ajax call to mongolab
var url = "https://api.mongolab.com/api/1/databases/bar/collections/profiles?apiKey=foo-"
var jsPromise = Promise.resolve($.ajax(url));
jsPromise.then(function(response) {
return response;
});
},
emitChange: function() {
this.emit(CHANGE_EVENT);
},
/**
* @param {function} callback
*/
addChangeListener: function(callback) {
this.on(CHANGE_EVENT, callback);
},
/**
* @param {function} callback
*/
removeChangeListener: function(callback) {
this.removeListener(CHANGE_EVENT, callback);
}
});
然后在我的组件中我有:
var ProfileApp = React.createClass({
getInitialState: function() {
return {
allProfiles: ProfileStore.getAll()
};
},
});
当我在 getAll() 函数中使用 console.log() 时,我可以看到结果,但是没有任何东西被传递给我的组件,关于如何解决这个问题的任何指针?