Questions tagged [knockout.js]

Knockout.js is an open source JavaScript library for dynamic HTML UIs using the Model-View-View Model (MVVM) pattern.

Knockout.js is an open source JavaScript library implementation of the Model-View-View Model (MVVM) UI pattern in JavaScript and HTML.

Knockout.js is a pure JavaScript library with no external dependencies. It is supported in all major browsers, IE 6+, Firefox 2+, Chrome, Opera, Safari (desktop/mobile).

Knockout.js works with any web framework.

The key features of Knockout.js include:

  • Free, open source (MIT license)
  • Small & lightweight — 55kb minified
  • Declarative Bindings: Easily associate DOM elements with model data using a concise, readable syntax.
  • Two-way binding: When your view model's state changes, your UI updates automatically. When you change form element values, the view model's state updates automatically.
  • Dependency Tracking: Implicitly set up chains of relationships between model data, to transform and combine it.
  • Templating: Quickly generate sophisticated, nested UIs as a function of your model data.
  • Components - 3.2.0+: Controls or Widgets made up of self-contained reusable chunks of code.

Helpful links

Stack Snippet Starter Pack

HTML:

<script src="//cdnjs.cloudflare.com/ajax/libs/knockout/3.4.0/knockout-debug.js"></script>

<p>First name: <input data-bind="value: firstName" /></p>
<p>Last name: <input data-bind="value: lastName" /></p>
<h2>Hello, <span data-bind="text: fullName"> </span>!</h2>

JavaScript:

var ViewModel = function(first, last) {
    this.firstName = ko.observable(first);
    this.lastName = ko.observable(last);
 
    this.fullName = ko.pureComputed(function() {
        return this.firstName() + " " + this.lastName();
    }, this);
};
 
ko.applyBindings(new ViewModel("Planet", "Earth")); 
20270 questions
4
votes
0 answers

Visual Studio 2017 unable to locate javascript nuget package files

I've recently installed visual studio 2017 and the problem i'm having is that i am unable to find .js files that are added through nuget packages. E.g. after adding knockout.js nuget package it shows up in dependencies but the .js file doesn't…
4
votes
3 answers

KnockoutJS - data-bind wont change text after button click

I have been struggling for a few days with knockout data binding. The simple yet very annoying example of problem that I struggle with is down below. I have a simple ViewModel class with a method that changes boolean from false to true. Knockout…
sarac
  • 43
  • 5
4
votes
1 answer

Dynamic Cascading Dropdown using AJAX

Objective: Based on the example found here. Populating dependent drop-downs with the data parsed in the getData() function using ajax calls. Currently my example is working with static data found in the ajax-mocks.js file, but I am unable to…
Ben Löffel
  • 931
  • 4
  • 12
  • 29
4
votes
2 answers

With KnockoutJS, how can I scroll to a component after it's rendered in a foreach?

I have deferred updates enabled. I have two components. The first is a list, which is simply implemented as a div with a foreach data binding: