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 8233995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:19:38+00:00 2026-06-07T18:19:38+00:00

Trying to update knockoutjs generated list, when i use jquery autocomplete functionality and select

  • 0

Trying to update knockoutjs generated list, when i use jquery autocomplete functionality and select some possible values. But list doesn’t update when i call the addItem function inside Select method. Expected behaviour would be that selected item value are added to knockoutjs items array.

MVC3 example view:

<input type="text" id="Name"/>

<h4>Items</h4>
<ul data-bind="foreach: items">
    <li>
        <span data-bind="text: $index"></span>:
        <span data-bind="text: name"></span>
        <span data-bind="text: code"></span>
        <a href="#" data-bind="click: $parent.removeItem">Remove</a>
    </li>
</ul>

<script type="text/javascript">
    $(function () {
        var appViewModel = new AppViewModel();
        function AppViewModel() {
            var self = this;

            self.items = ko.observableArray([]);

            self.addItem = function (name, code) {
                self.items.push({ name: name, code: code });
            };

            self.removeItem = function () {
                self.items.remove(this);
            };
        }

        $('#Name').autocomplete({
            minLength: 1,
            delay: 500,
            source: function (request, response) {
                $.ajax({
                    type: "POST",
                    url: "/Home/SearchItems",
                    dataType: "json",
                    data: { searchText: request.term },
                    success: function (data) {
                        if (data != undefined) {
                            response($.map(data, function (item) {
                                return {
                                    label: item.Name,
                                    value: item.Name,
                                    code: item.Code
                                };
                            }));
                        }
                    }
                });
            },
            select: function (event, ui) {
                appViewModel.addItem(ui.item.value, ui.item.code);
            }
        });

        ko.applyBindings(new AppViewModel());
    });
</script>
  • 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-07T18:19:40+00:00Added an answer on June 7, 2026 at 6:19 pm

    Here is a working version: http://jsfiddle.net/jearles/vya7V/

    Your problem was that you were instantiating a new AppViewModel in the ko.applyBindings statement, rather than passing in appViewModel that you instantiated earlier and are using in the select.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to update some old code from live() to use on() and something is
In trying to update my SDK to the latest, some things installed, but others*
I trying to update a model on a callback but the validation is causing
Im trying to update the contents of an element after running some php code.
I'm trying to update my code to use cv2.SURF() as opposed to cv2.FeatureDetector_create(SURF) and
I am trying to update a database with values from a csv file, the
Im trying to update some nested params from a form. I can see that
I am trying to update a KnockOutJS page using an Ajax call. The Update
Currently playing about with KnockoutJS. Just trying to update an observable array from a
I'm trying to use KnockoutJS to build an interactive dashboard with data bindings on

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.