Survey Questionnaire builder

已查看 19 次
跳至第一个未读帖子

Joebet Mutia

未读,
2016年9月26日 10:27:142016/9/26
收件人 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
回复全部
回复作者
转发
0 个新帖子