knockout-2.0

ASP.NET with Knockout variable length list with combobox - how to bind?

廉价感情. 提交于 2019-12-25 01:56:14
问题 With the following ASP.NET models public class User { public string Name { get; set; } public LEmail LEmail { get; set; } } public class LEmail { public IList<CLabel> Labels; public IList<CEmail> Emails; } public class CLabels { public IList<CLabel> Labels { get; set; } } public class CLabel { public string Name { get; set; } } public abstract class CEmail { public string SelectedLabel { get; set; } public string Name { get; set; } } Filling it out with dummy data and sending to appropriate

Iterating through a list of users and pushing to an array in knockout

别说谁变了你拦得住时间么 提交于 2019-12-24 22:50:36
问题 I have this script that returns a list of all users. I would like to have: set the viewModel's totalUsers and page properties based on data returned. Iterate through the list of users and push the last user object into the observableArry push() method adds users to already loaded and shown users Purpose I actually want to get a count of all users because i will be loading 20 users a page and when i reach the bottom of the page i will check if i still have more users to load and then load them

Data coming from an ObservableArray are displayed twice in my table

随声附和 提交于 2019-12-24 20:45:48
问题 here is my viewModel: ViewModel var sitesTableModel = [ { nameCol: "nameCol-1", pagesCol: "pagesCol-1", }, { nameCol: "nameCol-2", pagesCol: "pagesCol-2", }]; var pagesTableModel = [ { lastCol: "lastCol-1", editedCol: "editedCol-1", }, { lastCol: "lastCol-2", editedCol: "editedCol-2", }]; var viewModel = { sitesTable: ko.observableArray(sitesTableModel), pagesTable: ko.observableArray(pagesTableModel), }; then I call a webservice in this way: AJAX Call ajaxService = (function () { var

Identify the attribute change event in KnockoutJS?

自古美人都是妖i 提交于 2019-12-24 15:25:03
问题 Is there any way to Identify the attribute change event in KnockoutJS?? I found solutions in jQuery: firing event on DOM attribute change firing event on DOM attribute change But It would be good If I can do it with KO. Thanks. 回答1: If the attribute change is bound to a property in your view model, then you can simply subscribe to that property to get notified of changes. myViewModel.myProperty.subscribe(function(newValue) { alert("This property changed!!"); }); 来源: https://stackoverflow.com

Knockout UNable to Bind $root

孤人 提交于 2019-12-24 14:05:23
问题 Inside my Document i've added <div data-bind="text: ko.toJSON($root)"></div> to my html5 page. Unfortunately IE8 gives me an Error 'Unable to apply binding to $root' or similar. No Problems on FF and Chrome. How can i retuen a json dump of my current viewmodel for debugging needs? 回答1: I was able to repro your issue: the problem isn't with your binding but with the ko.toJSON call. Knockout uses the JSON.stringify function internally which fails in your case. Altough Is JSON.stringify()

Not able to trigger Knockout data-bind using jQuery

喜你入骨 提交于 2019-12-24 14:04:00
问题 I am writing a plugin using jQuery and knockout. I have two radio buttons. I am using knockout data-bind to check and uncheck the radio button. The problem is that when I am trying to uncheck the radio button on click of another button using jQuery, it is not updating bind observable property . <input type="radio" data-bind="checked: selectedVal" name="1" value="fixedPrice"/> Fixed Price <input class="hn" type="radio" data-bind="checked: selectedVal" name="1" value="allowBiding"/> Allow

observable not defined inside object literal knockout

瘦欲@ 提交于 2019-12-24 07:37:17
问题 I have a observable defined inside a object literal of a knockout viewmodel . Now when I ran the application .Its unable to access the observable . $(function () { var viewModel = { Folders: ['Inbox', 'Archive', 'Sent', 'Spam'], Title: ko.observable("My View Model Test"), SelectedFolder: ko.observable(), Mails: ko.observableArray(), SelectedMail: ko.observable(), SelectedChoices: ko.observable(false), navigate: function (folder) { SelectedFolder(folder); $.ajax({ url: "/Api/MailBox", data: {

knockout error - Uncaught Error: Unable to parse bindings.

▼魔方 西西 提交于 2019-12-24 00:35:20
问题 I get the following error when running my knockout code: Uncaught Error: Unable to parse bindings. Message: ReferenceError: measures is not defined; Bindings value: template: { name: 'measureDispTmpl', foreach: measures, as: 'food' } You can see the jsfiddle code here: http://jsfiddle.net/nickbuus/eUufc/ When I click the + icon I want the addMeasure method to be called - so that I can add a new measure to the current foodItem and save it. But when I try to call the addMeasure then the method:

Why doesn't ko.observableArray.length return length of underlying array?

落爺英雄遲暮 提交于 2019-12-23 13:16:02
问题 Using Knockout, when working with an observableArray , you must grab the underlying array ( myArray() ) in order to read the length. I don't understand why myArray.length wouldn't return the underlying array's length (instead it returns 0). Is this a bug or is there reason which I've simply missed? JSFiddle: http://jsfiddle.net/jsm11482/LJVWE/ JS/Model var data = { name: ko.observable("Test"), items: ko.observableArray([ { name: ko.observable("First Thing"), value: ko.observable(1) }, { name:

Does the simpleGrid require additional downloads?

。_饼干妹妹 提交于 2019-12-23 07:48:13
问题 I want to try the simpleGrid in a HotTowel project. When it came to: this.gridViewModel = new ko.simpleGrid.viewModel({ data: this.items, .... it threw an exception: Unable to get property 'viewModel' of undefined or null reference` I stepped through and found that ko.simpleGrid is undefined. Must any other files be added or is simpleGrid available from the standard Knockout.js library? 回答1: Check the fiddle (http://jsfiddle.net/rniemeyer/QSRBR/) provides in the Simple Grid sample. It need