Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8376465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:26:18+00:00 2026-06-09T15:26:18+00:00

I am trying to learn knockout and have come up against a problem. I

  • 0

I am trying to learn knockout and have come up against a problem.

I am trying to use the ko if clause but can’t seem to work it out myself

My script so far looks like

  <script>
    var SimpleListModel = function (items) {
        this.questionType = ko.observable("");
        this.items = ko.observableArray(items);
        this.itemToAdd = ko.observable("");
        this.addItem = function () {
            if (this.itemToAdd() != "") {
                var qt = $("#question-type").data("kendoDropDownList");
                this.questionType(qt.value());
                console.log(qt.value());
                this.items.push(this.itemToAdd()); // Adds the item. Writing to the "items" observableArray causes any associated UI to update.
                this.itemToAdd(""); // Clears the text box, because it's bound to the "itemToAdd" observable
            }
        }.bind(this);  // Ensure that "this" is always this view model
    };
    $(document).ready(function () {
        ko.applyBindings(new SimpleListModel([]));
    });
</script>

My html looks like

     <button type="submit" class="btn pull-right" data-bind="enable: itemToAdd().length > 0"><i class="icon-plus"></i>Add Question</button>
                        <div id="questions" data-bind="foreach: items">
                            <div class="question-item">
                                <label data-bind="text: $data" class="q-label"></label>
                                <textarea placeholder="Answer" class="q-answer"></textarea>
                                 <!-- ko if: questionType()==="ABC" -->
                                           Display ABC
                                <!-- /ko -->
                                <!-- ko if: questionType()==="DEF" -->
                                           Display DEF
                                <!-- /ko -->
                            </div>
                            <div class="clear"></div>
                        </div>

What do I need to do, to get the ko if: questionType to work correctly?

I have updated the setting of the questionType as suggested however I am getting an error Uncaught Error: Unable to parse bindings.
Message: ReferenceError: questionType is not defined;
Bindings value: if:questionType()==="Comment"

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T15:26:20+00:00Added an answer on June 9, 2026 at 3:26 pm

    Since questionType is an observable you need to call it as a function with no arguments to retrieve its value.

    So, your if statements would need to look like:

    <!-- ko if: $parent.questionType() === "ABC" -->
        Display ABC
    <!-- /ko -->
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to learn Sencha Touch 2 and I can't seem to find out how
trying to learn and practice arrays but I have a problem with this small
I am trying to learn to use Knockoutjs but I am facing a problem
Trying to learn PL/SQL with multimedia data. Can anyone please point out that from
I am somewhat new to jQuery but have been having fun trying learn about
I have been trying to learn from reading tutorials online and stuff but I
I am trying learn how to work with CEDET. I don't have any project
I am trying learn the use of lambda expressions and hence still struggling to
Trying to learn about php's arrays today. I have a set of arrays like
Im trying to learn a bit about c++ and have run in to some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.