当我找到该代码时,该代码未将其用于导出。似乎开源改为使用它来呈现为js文件并让div id显示内容。由于我的代码库
的很多原因,我不愿意这样做它不喜欢survey.onComplete
和surver.data
等。因为它们不在课堂上,但是我对React还是有点陌生,所以我想弄清楚如何使这项工作有效。也许是一些调查对象?
这是代码
import React from 'react';
import * as Survey from "survey-react";
import "survey-react/survey.css";
var surveyValueChanged = function (sender, options) {
var el = document.getElementById(options.name);
if (el) {
el.value = options.value;
}
};
var json = {
questions: [
{
type: "text",
name: "name",
title: "Your name:"
}, {
type: "text",
name: "email",
title: "Your e-mail"
}, {
type: "checkbox",
name: "car",
title: "What car are you driving?",
isRequired: true,
colCount: 4,
choices: [
"None",
"Ford",
"Vauxhall",
"Volkswagen",
"Nissan",
"Audi",
"Mercedes-Benz",
"BMW",
"Peugeot",
"Toyota",
"Citroen"
]
}
]
};
window.survey = new Survey.Model(json);
survey
.onComplete
.add(function (result) {
document
.querySelector('#surveyResult')
.textContent = "Result JSON:\n" + JSON.stringify(result.data, null, 3);
});
survey.data = {
name: 'John Doe',
email: 'johndoe@nobody.com',
car: ['Ford']
};
// ReactDOM.render(
// <Survey.Survey model={survey}
// onValueChanged={surveyValueChanged}/>,
// document.getElementById("surveyElement"));
class SurveyTest extends React.Component {
render()
{
var survey = new Survey.Model();
return(
<Survey.Survey model={survey}
onValueChanged={surveyValueChanged}/>
)
}
}
export default SurveyTest;
请注意,我注释掉的是代码库使用的语言。我更改为要导出的类,但后来遇到了问题。