1

YouTube Data API v3 にアクセスしようとしていますが、React でスクリプトを読み込む方法がわかりません。this.init()火事ですが、私は得gapi = {}ます。奇妙なことgapiに、コンソールに入ると、適切なオブジェクトとして表示されます。

TestPage = React.createClass({
  componentDidMount() {
    $.getScript("https://apis.google.com/js/client.js", this.handleClientLoad);
  },

  handleClientLoad(data, textStatus) {
    Utils.logObj(data, "data");
    Utils.logObj(textStatus, "textStatus");
    Utils.logObj(gapi, "gapi");
    Utils.logObj(window.gapi, "window.gapi");
  },

  render() {
    return (
      <div>This is the test page.</div>
    );
  }
});
4

1 に答える 1

3

コードは正常に動作し、コンソールを確認してください: http://jsfiddle.net/ferahl/ocpz7pbm/

var App = React.createClass({
  componentDidMount() {
    $.getScript("https://apis.google.com/js/client.js", this.handleClientLoad);
  },

  handleClientLoad() {
    console.log(window.gapi);
  },

  render() {
    return (
      <div>This is the test page.</div>
    );
  }
});

おそらく、あなたUtils.logObjは期待どおりに機能していませんか?

于 2015-11-06T11:43:53.603 に答える