Questions tagged [knockout-2.0]

Knockout.js is an open source JavaScript library for dynamic HTML UIs using the Model-View-View Model (MVVM) pattern. This tag is for questions specific to the 2.0 releases.

Knockout.js is an open source JavaScript implementation of the Model-View-ViewModel (MVVM) UI pattern. This tag is for version 2.0 specific questions. See also the main tag for general information about Knockout.js.

Version 2.0 of Knockout.js as announced by its creator included the following new features:

  1. Control flow bindings such as if, ifnot, with, and foreach;
  2. Containerless control flow, e.g. <!-- ko foreach: products -->;
  3. Access to parent binding contexts through contextual variables such as $parent;
  4. Cleaner event handling using the click binding;
  5. Binding providers (and hence external bindings)
  6. Throttling by extending observables.

Find the v2.0.0 source on GitHub.

1009 questions
35
votes
6 answers

Knockout.js Make every nested object an Observable

I am using Knockout.js as a MVVM library to bind my data to some pages. I'm currently building a library to make REST calls to a web service. My RESTful web service returns a simple structure: { id : 1, details: { name: "Johnny", …
frapontillo
  • 10,499
  • 11
  • 43
  • 54
24
votes
2 answers

Radio buttons Knockoutjs

I have 2 values that I get from server A and B. I can only have one true at a time. Again what I need is one of the radios to be checked at a time so one true value only. var viewModel = { radioSelectedOptionValue: ko.observable("false"), …
NoviceDeveloper
  • 1,270
  • 3
  • 15
  • 41
24
votes
3 answers

Knockout JS: Stop divs binded to visible: from flashing on screen

I am working on a single page applications that has a bunch of hidden divs, binded (or is it bound?) to KnockoutJS with visible:. When page loads, they all momentarily flash on screen. I have tried moving my JS into the , but that had…
solefald
  • 1,739
  • 1
  • 15
  • 29
24
votes
4 answers

Knockoutjs (version 2.1.0): bind boolean value to select box

I want to bind boolean value to select element using KO v2.1.0, but obviously it doesn't work as expected. HTML code: JavaScript…
Gelin Luo
  • 14,035
  • 27
  • 86
  • 139
22
votes
2 answers

knockout - HTML href

I have a foreach loop that goes through an array (filesObservableArray). The array has a key/value with the key: URLPath. When I bind the array within the HTML, I would like to set the 'href=' value with the URLPath. I know this part is a fail, but…
nanonerd
  • 1,964
  • 6
  • 23
  • 49
22
votes
2 answers

knockoutjs get element id through click event

I'm using knockoutjs and I currently have something in my view that looks like this: This allows me to get the element ID in my view…
bdev
  • 2,060
  • 5
  • 24
  • 32
20
votes
10 answers

make an input only-numeric type on knockout

i read many tutorials but i dont know how to do this, this is the input input(type="text",name="price",id="price"data-bind="text: price,valueUpdate:['afterkeydown','propertychange','input']") and this is my viewModel price:…
andrescabana86
  • 1,778
  • 8
  • 30
  • 56
20
votes
2 answers

Large scale KnockoutJS application architecture

I love KnockoutJS but have been struggling to figure out the best way to build large scale Javascript applications with it. Right now the way I'm handling the code is by building with a root view model which usually starts at the master page level…
Ryan
  • 4,354
  • 2
  • 42
  • 78
18
votes
3 answers

Knockout-2.2.0, subscribe get value before change AND new value

jsfiddle link: http://jsfiddle.net/T8ee7/ When I call Knockout's subscribe method is there a way I can get both the previous and new value? Right now, I can only call get these values separately. I want to trigger some code if the old and new value…
Abe
  • 6,386
  • 12
  • 46
  • 75
18
votes
2 answers

Knockout serialization with ko.toJSON - how to ignore properties that are null

When using: var dataToSave = ko.toJSON(myViewModel); .. is it possible to not serialize values that are null? Serializing my current viewModel creates around 500Kb of JSON most of which is ends up like: "SomeObject": { "Property1": 12345, …
Mark Robinson
  • 13,128
  • 13
  • 63
  • 81
16
votes
1 answer

knockout, whats the best way to find a value in observableArray

I have an observableArray, I have a name "Zippy", I need to check if it is in the array. if this name exists, I need to get its type. how should I do that? // This observable array initially contains three objects var anotherObservableArray =…
qinking126
  • 11,385
  • 25
  • 74
  • 124
16
votes
2 answers

Knockout Validation async validators: Is this a bug or am I doing something wrong?

I really like how Eric Barnard's knockout validation lib integrates with observables, allows grouping, & offers custom validator pluggability (including on-the-fly validators). There are a couple of places where it could be more UX…
danludwig
  • 46,965
  • 25
  • 159
  • 237
15
votes
3 answers

Knockout default text when `foreach` is empty

Bearing in mind that similar questions have been answered here, I was wondering how one might go about having default text or HTML display inside a Knockout data-bind='foreach: list' whenever the list is empty. The solutions on the linked page don't…
Brian M. Hunt
  • 81,008
  • 74
  • 230
  • 343
15
votes
2 answers

Knockout: click & checked bindings in one element

I have array of limits, and checkboxes for enable/disable limits. But checkboxes do not work jsFiddle function Limit(start, end) { var that = this; this.start = start; this.end = end; this.label = ko.computed(function(){ …
Ozerich
  • 2,000
  • 1
  • 18
  • 25
14
votes
3 answers

KnockoutJS - Frustrations with ko.computed and an AJAX request

I am simply trying to pull some data from an ajax request. The ajax call works - I know the data is retrieved. But it just isn't setting the value of the ko.computed... function viewModel() { this.Id =…
Ciel
  • 17,312
  • 21
  • 104
  • 199
1
2
3
67 68