knockout.js

ko.js: Dynamically generated radio buttons and 'checked' dependent computations

眉间皱痕 提交于 2019-12-25 03:14:16
问题 tl;dr : I use an ajax-retrieved array of objects to generate a list of radio buttons. When a radio button is checked , I want to make compute on the selected object and save the value inside a ko.observable() which is then shown in the HTML document via data-bind . Here's what I did: Firstly, I am retrieving array of user objects (via ajax): var ViewModel = function() { var self = this; // an array of retrieved user objects self.retrievedUsers = ko.observableArray([]); self.getUsers =

Parse JSON in Knockout into Dictionary Key Value in C#

杀马特。学长 韩版系。学妹 提交于 2019-12-25 03:00:16
问题 I have following knockout text binding : <td><strong><span id="texthotelcode" data-bind="text: parameters" /></strong></td> data binding of text: which returns data: {"id1":"2Z94","id2":"9861"} now I want to convert them from this JSON into Key and value in Dictionary in C# as string, string Any idea for this case thanks 回答1: .net can deserialize JSON in the following form into c# dictionary: dict: [ { "Key": "id1", "Value": "2Z94" }, { "Key": "id2", "Value": "9861" } ] So you can use a

How to push object to an observableArray

北城以北 提交于 2019-12-25 02:58:51
问题 I have this model, a Foo have many FooItem . How can I add an object to a FooItem ? I have this code, you can suggest or even erase the whole code that works best for this scenario var Foo = function (selected) { this.id = ko.observable(); this.name = ko.observable(); this.fooItems = ko.observableArray([]); this.isSelected = ko.computed(function() { return selected() === this; }, this); }; var FooItem = function () { this.id = ko.observable(); this.selectedItemId = ko.observable(); this

KnockOut JS - Binding a button to an item in a collection

巧了我就是萌 提交于 2019-12-25 02:58:43
问题 This is a slightly tricky question to put into words. Basically I've been trying to build a shopping cart page in KnockoutJS based on one of the examples in the the KnockoutJS website (http://knockoutjs.com/examples/cartEditor.html). However I wanted to make use of jQueryUI sliders so that I could adjust the values of each product in my cart. This I've managed to get working OK and I can add a product (in this case Motorcars) to my basket and adjust the value and also increase/decrease the

Knockout Add and Edit observableArray Conflict

笑着哭i 提交于 2019-12-25 02:54:03
问题 I have an observableArray which is displayed in a table using foreach binding where values are displayed inside textboxes. Now what I want to do is to add an edit link on each row which enables/disables the readonly state of the corresponding textbox in its row. I can do it, but the way I did it messed up my add new line (push) functionality. Here is a fiddle of my code. Try to delete a line then add it again by selecting it in the dropdown list, the edit link disappears as well as the value.

Javascript + Knockout.js memory leak - How to make sure object is being destroyed?

安稳与你 提交于 2019-12-25 02:51:57
问题 I am using google's 3 Snapshot method to find memory leaks on the page. Page is running on Knockout.js and Jquery Mobile UI. I have already narrowed down to one of memory leaking divs. Between each snapshot I am running this script to clear the memory leaking object. $('.paddedContentContainer').children().each(function(index,item){ console.log(item); $(item).off(); ko.cleanNode($(item)); $(item).remove(); item = null; }); .paddedContentContainer is parent of leaking object. Now the

Knockout - validation showing same error message twice

倾然丶 夕夏残阳落幕 提交于 2019-12-25 02:45:28
问题 I am using knockout validation plugin to validate a simple form field , validation is working but it is showing same error message twice below text box. my code follows JS viewmodel $(document).ready(function () { ko.validation.registerExtenders(); ko.validation.configure({ registerExtenders: true, messagesOnModified: false, insertMessages: false, parseInputAttributes: true, messageTemplate: null }); ko.validation.init(); var vm = new viewmodel(); ko.applyBindings(vm, document.getElementById(

How do I show a Knockout observable value in an editable field without changing the value

我只是一个虾纸丫 提交于 2019-12-25 02:43:39
问题 I'm trying to create a modal window used to get values from the user to send off to a server. I want to prepopulate the fields with the values that we currently have, and have them update with the current values (stored locally) when the modal window appears. The issue I'm running into is that when I link the fields to the observable directly, the user will edit the fields and if they hit 'Cancel', the values the previous screen shows will contain the updated values. If I bind it like "value:

Setting the value of an input when using foreach in knockout

99封情书 提交于 2019-12-25 02:34:10
问题 I am using the attr binding to set the name and value of an input tag. The problem is I don't know the binding to use for the value. I have tried text and value so far but with no luck. My code looks like this: <div data-bind="foreach: witnesses"> <input data-bind="attr: { name: 'firstName', text: firstName }"/> </div> I am hoping that this will render as: <input name='firstName value=`enter code here`'Joe'> or even <input name='firstName'>Jo`enter code here`e</input> How to achieve this?

Edit functionality in form using knockout js

帅比萌擦擦* 提交于 2019-12-25 02:26:56
问题 Hi i am working on a form using knockout js i have to perform CRUD operation. Out of these i am able to do all except update(edit). I want on click of edit same form will open as open on click on addperson but with the values of person. here is my code <html> <head> <script type="text/javascript" src="jquery.min.js"></script> <script type="text/javascript" src="knockout-3.1.0.js"></script> </head> <body> <a href="#" data-bind="click:addFields">ADDPerson</a> <a href="#" data-bind="click