Вот рабочий файл Survey.js с примером реакции: ?p=предварительный просмотр
В моем html также есть заголовок <script src="https://unpkg.com/survey-react"></script>
.
В моем main.jsx я вызываю рендеринг div, который будет заполнен на основе файла json и нескольких компонентов реагирования, в моем массиве json у меня также есть объект json вопросов для Survey.js. Чего я хотел бы добиться, так это отобразить опрос, когда объект вопросов достигается при разборе массива.
В моем компоненте верхнего уровня у меня есть этот вызов:
if (section.hasOwnProperty('questions')){
return <Questions key={i+"questions"} id={i+"questions"} questions={section.questions} />;
Вопросы.jsx:
var React = require('react');
var ReactDOM = require('react-dom');
var Survey = require('survey-react');
var Questions = React.createClass({
render: function() {
Survey.Survey.cssType = "bootstrap";
Survey.defaultBootstrapCss.navigationButton = "btn btn-green";
window[this.props.id] = new Survey.Model( this.props.questions );
var questionid = this.props.id;
var idi = this.props.id.replace("questions","");
return (
<dt>
<div id={this.props.id}></div>
</div>
</dt>
);
}
});
module.exports = Questions;
ReactDOM.render(<Survey.Survey model={window[questionid]} />, document.getElementById({questionid}));
Он компилируется без ошибок, но затем в браузере я получаю ошибки консоли:
Ошибка типа: WEBPACK_IMPORTED_MODULE
<script src="https://unpkg.com/survey-react"></script>
react не определено[Подробнее] ReferenceError: идентификатор вопроса не определен
Кажется, я пытаюсь сделать это неправильно, но как сделать это правильно? Я новичок в реагировании и не знаком с использованием reactDOM внутри компонента, и это также мой первый проект в Survey.js.
Спасибо за помощь.