我有一个反应类如下:
var AllMeals = React.createClass({
....
concatMeal: function(new_meal) {
newState = this.state.meals.concat(new_meal);
this.setState({ meals: newState });
},
....
});
module.exports = AllMeals
components.js看起来像这样
require('./constants')
....
window.AllMeals = require('./components/all_meals');
....
application.js看起来像这样
//= require jquery
//= require jquery_ujs
//= require twitter/bootstrap
//= require react
//= require react_ujs
//= require react_router
//= require react_router_ujs
//= require cable
//= require components
//= require_tree .
但是,当我在concatMeal
文件中的window.AllMeals
之外调用meal.coffee
函数时,我会得到window.AllMeals.concatMeal is not a function
App.meal = App.cable.subscriptions.create "MealChannel",
received: (data) ->
unless data.raw_html_for_meals_index.blank?
window.AllMeals.concatMeal(data.raw_html_for_meals_index)
我做错了什么?