Question T4848
Visible to All Users

Create new questions on the page

created 5 years ago (modified 5 years ago)

[Ticket cloned from T4563: I would like to trigger an event after click  the delete button]

Hello Team

I am retreiving this type of JSON  {"type":"text","name":"question1","QuestionID":49}   from data database, I would like to create a page with this type of JSON
 EX: {"type":"text","name":"question1","QuestionID":49}
      {"type":"text","name":"question1","QuestionID":49}
     {"type":"text","name":"question1","QuestionID":49}
NB if you have three  object as mention below, I would like to have three question on the page1. how do I do that?

On 6/30/2020 12:53 PM, Serge T [surveyjs Support] wrote:

Comments (1)

    Sorry, could you please describe your task more?
    Do you want to create it in SurveyJS Creator or SurveyJS Library (runner)?
    Why can't you use creator.JSON = myJSON; or var survey = new Survey(myJSON);

    In general, the code for creating a new question from JSON and add it into the current page should be the following.
    For Library:

    JavaScript
    var question = Survey.Serializer.createClass(yourJSON.name); question.fromJSON(yourJSON); survey.currentPage.addQuestion(question);

    For creator:

    JavaScript
    var question = Survey.Serializer.createClass(yourJSON.name); question.fromJSON(yourJSON); creator.survey.currentPage.addQuestion(question);

    Thank you,
    Andrew
    SurveyJS Team