Twitter bootstrap 3 Modal with knockout

bootstrap modal provided events, you just need to hook up event ‘hidden.bs.modal’. BTW, do proper disposal too. http://jsfiddle.net/C8w8v/377/ ko.bindingHandlers.modal = { init: function (element, valueAccessor) { $(element).modal({ show: false }); var value = valueAccessor(); if (ko.isObservable(value)) { // Update 28/02/2018 // Thank @HeyJude for fixing a bug on // double “hide.bs.modal” event firing. // Use … Read more

Knockout JS mapping plugin without initial data / empty form

A couple of options for you besides just manually managing your view model. The mapping plugin supports a create callback that lets you customize how it gets created. This can be used to add default properties to an object, if they happen to be missing. Something like this: http://jsfiddle.net/rniemeyer/WQGVC/ Another alternative is to use a … Read more

Adding properties to the view model created by using the Knockout JS mapping plugin

You need to use a create method on the mapping object itself like: var mapping = { //customize at the root level. create: function(options) { //first map the vm like normal var vm = ko.mapping.fromJS(options.data); //now manipulate the returned vm in any way that you like vm.someProperty = “test”; vm.someComputed = ko.computed(function() { return vm.first() … 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

Javascript Equivalent to C# LINQ Select

Yes, Array.map() or $.map() does the same thing. //array.map: var ids = this.fruits.map(function(v){ return v.Id; }); //jQuery.map: var ids2 = $.map(this.fruits, function (v){ return v.Id; }); console.log(ids, ids2); http://jsfiddle.net/NsCXJ/1/ Since array.map isn’t supported in older browsers, I suggest that you stick with the jQuery method. If you prefer the other one for some reason you … Read more

Using knockout js with jquery ui sliders

Here is an example: http://jsfiddle.net/jearles/Dt7Ka/ I use a custom binding to integrate the jquery-ui slider and use Knockout to capture the inputs and calculate the net amount. — UI <h2>Slider Demo</h2> Savings: <input data-bind=”value: savings, valueUpdate: ‘afterkeydown'” /> <div style=”margin: 10px” data-bind=”slider: savings, sliderOptions: {min: 0, max: 100, range: ‘min’, step: 1}”></div> Spent: <input data-bind=”value: … Read more