Survey Questionnaire builder

19 views
Skip to first unread message

Joebet Mutia

unread,
Sep 26, 2016, 10:27:14 AM9/26/16
to KnockoutJS
Good day guys...

Im a newbie on using knockout and i would like to ask if the path im taking is the correct one..

My problem is i needed to create a dynamic questionnaire base on the values in a json... im planning to use KO sincei found out that it will be easy to bind the objects...so i started on having this

 self.dataModel = ko.mapping.fromJS(JSON.parse($("#JsonData").val()));

to have an autoobservable for all values in the json... then i have this

 $.each(self.dataModel.questions(), function (index, element) {

                var question_id = 'question_id_' + this.questionid();

                console.log(question_id)

                //clone the template
                var template = $('.question-container.template').clone();

                //remove template class
                template.removeClass('template')

                //edit id
                template.attr('id', question_id);

                //inject the template to the main questionnaire
                $("#main_question_container").append(commonModule.GetOuterHTML(template));

                //add the answers here





                var theQuestion = $("#main_question_container").find('#' + question_id)


                //bind it
                ko.applyBindings(self, $("#" + question_id)[0]);

            });


this is the template

<section class="question-container template" data-bind="attr: { 'data-question': this.questionid }">

    <span data-bind="text: this.description"></span>
  
</section>

My problem is every loop this.description is not getting the loop i have on the for each above.. what im after is to dynamically create the html and do the bindings inside that...

can someone please guide me.

thanks
Reply all
Reply to author
Forward
0 new messages