我用jquery和materializecss制作了一个页面,其中所有的js都很好地运行。但是当我将它转移到reactJs组件时,其中一个js脚本停止工作了。
这是组件。正如您所看到的,上面还有另一个来自同一materialize.min.js的js初始化,而且它完美地工作。为什么第二个不行呢?
这是组件。正如您所看到的,上面还有另一个来自同一materialize.min.js的js初始化,而且它完美地工作。为什么第二个不行呢?
var React = require('react');
var CharSpy = React.createClass({
componentDidMount: function() {
// this one works well
$('.scrollspy').scrollSpy();
// this one doesn't work
$('.tabs-wrapper').pushpin({ offset: 65 });
},
render: function() {
return (
<div className="tabs-wrapper">
<ul className="section table-of-contents">
<li><a href="#user"><span className="hide-on-small-only">Профиль</span></a></li>
<li><a href="#abilities"><span className="hide-on-small-only">Способности</span></a></li>
<li><a href="#activity"><span className="hide-on-small-only">Статистика</span></a></li>
<li><a href="#skillmap"><span className="hide-on-small-only">Карта</span></a></li>
<li><a href="#comments"><span className="hide-on-small-only">Комментарии</span></a></li>
</ul>
</div>
);
}
});
module.exports = CharSpy;
错误:
Uncaught TypeError: $(...).pushpin is not a function
React.createClass.componentDidMount @ main.js:22993
assign.notifyAll @ main.js:3920O
N_DOM_READY_QUEUEING.close @ main.js:17089
Mixin.closeAll @ main.js:19861
Mixin.perform @ main.js:19802
batchedMountComponentIntoNode @ main.js:15144
Mixin.perform @ main.js:19788
ReactDefaultBatchingStrategy.batchedUpdates @ main.js:12271
batchedUpdates @ main.js:18015
ReactMount._renderNewRootComponent @ main.js:15279
ReactPerf.measure.wrapper @ main.js:16518
ReactMount.render @ main.js:15368
ReactPerf.measure.wrapper @ main.js:16518
(anonymous function) @ main.js:23680
React.createClass.statics.run.dispatchHandler @ main.js:1852(
anonymous function) @ main.js:1820(
anonymous function) @ main.js:874(a
nonymous function) @ main.js:874Tr
ansition.to @ main.js:877(a
nonymous function) @ main.js:1819T
ransition.from @ main.js:856di
spatch @ main.js:1816r
efresh @ main.js:1867r
un @ main.js:1863r
unRouter @ main.js:25552
25../components/app @ main.js:23679
s @ main.js:1e @
main.js:1(ano
nymous function)