End Your If

Helping you solve those tough coding problems!

Learn some great development tips and techniques through recipes that clearly define the problem being solved with a working solution.
Popular Tags: cakephp | theory | optimization | javascript-development | asp-net | ajax | sql | php-development | css | php

Follow @endyourif rss Facebook LinkedIn
My Books

Knockout: `this` context with computed observables and subscribe Knockout: `this` context with computed observables and subscribe

Published on May 29, 2017 by Jamie Munro

In JavaScript, the `this` variable inside a function (like a computed observable or a Knockout subscribe) function can be an extremely useful variable to access related properties to your observable.  Learning the following behavior has opened many doors for me when leveraging the Knockout.js framework.

Read more >

Tags: KnockoutJS | knockoutjs | this

Convert the (un)check all to a #KnockoutJS Component Convert the (un)check all to a #KnockoutJS Component

Published on Apr 29, 2015 by Jamie Munro


You've created a nice feature leveraging Knockout.js and now you want to re-use this feature on another page, another site, or in a slightly different fashion. This example will extend the previous (Un)Check All using #KnockoutJS and make it easily re-usable.


A Knockout component can be created using a mixture of HTML (with data bindings) and a Knockout ViewModel. By altering the previous check all example and making it slightly more re-usable, it can be easily added to other pages with minimal effort. If you are not already familiar with the example being extended, please take a minute and give the (Un)Check All using #KnockoutJS a quick read.

Once the component is created, it can be included on any page with this simple HTML:
<checkall params="items: items, selectedItems: selectedItems"></checkall>

Read more >

Tags: KnockoutJS | knockoutjs | component

Replacing Radio Buttons with a Button Group using Bootstrap and #KnockoutJS Replacing Radio Buttons with a Button Group using Bootstrap and #KnockoutJS

Published on Apr 27, 2015 by Jamie Munro


Radio buttons are hard-to-see, not easy to select, and let's face it, quite mundane. You would like to replace these radio buttons with a group of buttons that represent the same functionality, e.g. only one of the options may be selected at any given time.


Leveraging Bootstrap which provides many incredibly styled components for buttons, alert boxes, tables, forms, etc... regular radio buttons will be replaced by a button group (see screenshot below). Knockout.js will be used to create a custom data binding that will make the group of buttons act like regular radio buttons (with a nicer look of course).


This example assumes you have a basic understanding of both Bootstrap and Knockout.js. If you don't, feel free to explore my latest book ASP.NET MVC 5 with Bootstrap and Knockout.js for a great introduction, plus many more examples.

The versions used for this example are 3.3.4 for Bootstrap and 3.3 for Knockout.js. This example should be compatible with older versions of these frameworks.

Read more >

Tags: KnockoutJS | knockoutjs | Bootstrap | bootstrap | radio buttons | buttons

(Un)Check All using #KnockoutJS (Un)Check All using #KnockoutJS

Published on Apr 23, 2015 by Jamie Munro

When I wrote Knockout.js: Building Dynamic Client-Side Web Applications I was trying to focus on demonstrating specific things, such as custom bindings, extending observables, etc. Unfortunately this didn't leave room for what I would call "random" examples of things that I do on a semi-regular basis. This blog post will demonstrate how to create a (un)check all list of checkboxes.

If I haven't said it before, examples like this are why I love working with Knockout.js on a daily basis. This example is accomplished in under 50 lines of code, with most of it being whitespace for readability!

The following example assumes you understand how to install Knockout.js and have a brief understanding of Knockout ViewModels. If you are looking for a good introduction *cough* *cough*, my book does an excellent job of it ;)


You have a list of elements - such as emails or any other list of data - and you want to provide the user a one-click button to select (or unselect) all items in the list. A nice added bonus, you want to automatically update the "global" checkbox indicating when all items are checked (and unchecking it when all items are not checked).


This problem can be solved by leveraging a computed observable. With Knockout.js, computed observables are re-evaluated each time an observable variable changes in the computed function. To avoid a circular reference, a writable computed observable will be used to force the (un)checking of all items.

This example is using Knockout.js version 3.3; however, it should be compatible with older versions as well.

Read more >

Tags: KnockoutJS | knockoutjs

ASP.NET MVC 5 with Bootstrap and Knockout.js ASP.NET MVC 5 with Bootstrap and Knockout.js

Published on Apr 21, 2015 by Jamie Munro

I can't believe 9 months has gone by since I came to an agreement on writing two books with O'Reilly Media! The first book was on Knockout.js which is a great framework that focuses on the Model-View-ViewModel (MVVM) architecture pattern. I finished the initial draft at the end of September 2014. During October and November, I multi-tasked by writing the second book while working through copy edits and multiple rounds of QC on the first book.

The first book official released (in e-book format) in December with the print version releasing early in January.

December, January, and February were all busy months while I was working on the second book. I cannot stress how difficult this book was to write. Each chapter would take days to write, tweak, and finalize.

March, and now April contained more copy edits and QC rounds for the second book. I think the book is about to be finalized and the e-book version should be ready sometime in the middle of May with the print copy following shortly after!

As the title of this blog states, the book is titled ASP.NET MVC 5 with Bootstrap and Knockout.js. The (un)official back cover reads as follows:

"Bring dynamic server-side web content and responsive web design together to build websites that work and display well on any resolution, desktop or mobile. With this practical book, you’ll learn how by combining the ASP.NET MVC server-side language, the Bootstrap front-end framework, and Knockout.js—the JavaScript implementation of the Model-View-ViewModel pattern.

Author Jamie Munro introduces these and other related technologies by having you work with sophisticated web forms. By the end of the book, experienced and aspiring web developers alike will learn how to build a complete shopping cart that demonstrates how these technologies interact with each other in a sleek, dynamic, and responsive web application.

  • Build well-organized, easy-to-maintain web applications by letting ASP.NET MVC 5, Bootstrap, and Knockout.js do the heavy lifting

  • Use ASP.NET MVC 5 to build server-side web applications, interact with a database, and dynamically render HTML

  • Create sleek and responsive views with Bootstrap that render on a variety of modern devices; you may never code with CSS again

  • Add Knockout.js to enhance responsive web design with snappy client-side interactions driven by your server-side web application"

I think this does a great job of describing why I chose these three technologies for the book and how they come together allowing you to easily build dynamic and responsive websites.

While writing these two books I jotted down a lot of ideas for examples. Unfortunately (or fortunately), I was unable to include them all into the books. So over the next little while, I will work to bring them as examples on my blog. Stay tuned. If you have any questions about the books, feel free to post questions/comments here on my blog or find me on Twitter @endyourif

Read more >

Tags: ASP.NET | JavaScript | KnockoutJS | Bootstrap

Knockout - Uncaught ReferenceError: Unable to process binding Knockout - Uncaught ReferenceError: Unable to process binding

Published on Oct 27, 2014 by Jamie Munro