How to use indexOf in KnockoutJS

An observableArray exposes a method called indexOf, which is a wrapper to ko.utils.arrayIndexOf that simply loops through the array looking for the item that you pass to it. So, if you have the item you can do: var viewModel = { items: ko.observableArray([{id: 1, name: “one”}, {id:2, name: “two”}]) }; var item = viewModel.items()[1]; console.log(viewModel.items.indexOf(item)); … Read more

What’s the applyBindings’ second parameter used for?

KnockoutJS is open source. From the relevant file: ko.applyBindings = function (viewModelOrBindingContext, rootNode) { // Some code omitted for brevity… if (rootNode && (rootNode.nodeType !== 1) && (rootNode.nodeType !== 8)) throw new Error(“ko.applyBindings: first parameter should be your view model; second parameter should be a DOM node”); rootNode = rootNode || window.document.body; // Make “rootNode” … Read more

Knockout.js “if Binding” on multiple booleans

When Knockout processes your bindings it first evaluates your expression. If the expression results in an observable, it then evaluates the observable as a convenience to get the final value that the if: works on. So the two following work identically <div data-bind=”if: foo”></div> <div data-bind=”if: foo()”></div> Once you leave the world of simple expressions … Read more

How do I define a knockout binding handler in typescript?

Defining a custom binding handler Its actually pretty easy, just add it (myBindingHandler) to the KnockoutBindingHandlers interface right before you define your custom binding handler. Please note that you have to do make this addition to the interface, within a .d.ts file as of version 1.0 (or possibly earlier). bindingHandlers.d.ts /// <reference path=”typings/knockout/knockout.d.ts” /> interface … Read more

Performance tuning a knockout application – guidelines for improving response times

I think that it would be too much to layout the tips that I have in mind in one answer. I started a series of blog posts on this topic. The first post is here. This post describes a bit how if/with work (copies the children as its template and re-renders using the template whenever … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)