FAQ Database Discussion Community


Knockout - How to reset Dynamic observable array with new value

javascript,knockout.js,lazy-loading,observablecollection
I can't reset observable array with new value am using some lazy loading Technic. I can clear but can't reset, but it not allowing me to add new dynamic value. fiddle http://jsfiddle.net/kspxa8as/ js var i = 1; optionsProvider = function(self) { var self = self || {}; self.options = {};...

knockout how to get $parent of $parent

jquery,knockout.js
<div id="root" data-bind="with: $data.Building"> <div data-bind="foreach: $data.Offices"> <div data-bind="foreach: $data.desks"> <div data-bind="foreach: $data.Legs"> <button class="btnDestroyDeskLeg"> Destroy</button> </div> </div> </div> </div> <script> $("#root").on('click', '.btnDestroyDeskLeg', function () { var context = ko.contextFor(this), Office = ** ? **, Desk = context.$parent, Leg = context.$data; }); </script> How can I get $Parent of $Parent?...

How to call a nested function from out side knockout js

knockout.js
i am learning knockout js. so still my understanding is not very clear. so apologized to ask this kind of question. see the code first to see what i am trying to achieve. here is jsfiddle link http://jsfiddle.net/tridip/vvdvgnfh/ <button data-bind="click: $root.printproduct()">Print Product</button> <table id="table1" cellspacing="0" cellpadding="0" border="0"> <tr> <th style="width:150px">Product</th>...

Change CSS of element in after Move event of Knockout sortable

css,knockout.js,knockout-sortable
I want to change the CSS of an element once it is dragged and dropped (afterMove event) to a container using the knockout sortable library. I tried getting the ID of the div containing the element and modifying its CSS in the afterMove event as: document.getElementById('container').style.backgroundColor="yellow"; The above code does...

Knockout JS Validation not working

javascript,asp.net-mvc,knockout.js
I am a newbie in Knockout JS. i want to apply validations in KO. i have used plugin knockout.validation.min.js . I have implemented it like this but not working My View Model $(document).ready(function myfunction() { ko.applyBindings(new EmployeeKoViewModel()); }) var EmployeeKoViewModel = function () { var self = this; self.EmpId =...

How to capture table row on button click to add css class knockout js

css,json,knockout.js
i have table with data and data populated by knockout js foreach bind. i would like to know how to access specific table row's data when it gets updated. if i could access table row then could add css class to that tr. my objective is to do bit color...

knockout js css biniding doesn't save changes

javascript,knockout.js
knockout js css biniding doesn't save changes after div's class was changed: My model contain 2 properties: man: '', woman: 'active' And I have 2 element in dom, which classes can be changed. <input type='button' value='Is MAN?' class='' data-bind='css: man'> <input type='button' value='Is WOMAN?' class='' data-bind='css: woman'> I want to...

How can I add HTML to this Knockout.js Viewmodel variable? [duplicate]

javascript,html,knockout.js,knockout-components,knockout-templating
This question already has an answer here: HTML Entities with Knockout 1 answer I have a list of steps displayed on the page. Some steps (but not all) will have 1-3 substeps. I was thinking the simplest way of doing this was to just write the HTML manually within...

Why one property is not getting observable knockout.js

knockout.js
Here is my full code. When I run the program it is working but when I change the quantity value then subtotal is not getting changed. If possible, could someone please go through my code and tell me which area I need to fix in the code? Full Code <table...

Css negation giving type error

knockout.js,knockout-2.0
In my model I have self.isAssetForTradingEnabled = false; and when I try to bind it to add some style like this: <tr data-bind="css: { 'selected': quantity() > 0 , 'disabled': !isAssetForTradingEnabled() }"> Then Knockout gives a type error. It works if I change isAssetForTradingEnabled = true; and 'disabled': isAssetForTradingEnabled ...

Knockout.js: Filter array on subscribe

javascript,knockout.js
I have an observableArray that in its subscribe callback I need to filter the new array passed. For example: myArray.subscribe(function(elements) { ko.utils.arrayFilter(elements, function(element) { return element.x > 10 }) }) This, of course, doesn't work since arrayFilter nor the native filter() method doesn't change the original array. The problem is...

Knockout - How to keep template inputs in sync with observable array when adding?

javascript,knockout.js
I am using a foreach template with knock out. I have a binding in my page <div data-bind="template: { name:'myList', foreach: viewModel.myList}</div> In my template, I have an attr binding on an input: data-bind="attr: { value: $data.Desc }" viewModel.myList.push(listItem); I then convert my view model to JSON: var json =...

Modular Web Components with View-Based Data-Binding context

javascript,html,knockout.js,data-binding
I'm trying to make my code as modular as possible and mimic the patterns of WPF and Caliburn.Micro. Here's what I've tried so far using Knockout components. Component ViewModel function welcomeViewModel() { this.greeting = 'Hello world!; } App ViewModel function appViewModel() { this.firstGreetingVM = new welcomeViewModel(); this.secondGreetingVM = new welcomeViewModel();...

Observe MyArray().length knock out

javascript,knockout.js
Is it possible to store length on an observable array in an observable variable and bind this to the view, something like this? self.MyArray = ko.observableArray([]); self.MyArraylength = self.MyArray().length; //Bind in view self.Observelength = ko.observable(self.MyArraylength); When I alert MyArray length it seems to update proper, but cant get it to...

Getting error regarding calling a custom function from binding formatCurrency()

javascript,knockout.js
Error message is ReferenceError: formatCurrency is not defined here is my jsfiddle http://jsfiddle.net/tridip/3bu6nybk/ please some one see my jsfiddle link and tell me why i am getting this error message Error message is ReferenceError: formatCurrency is not defined formatCurrency is defined in same place function formatCurrency(value) { alert(value.toFixed(2)); return "$"...

Knockout dynamic