knockout-2.0

knockout unable to process binding “foreach”

允我心安 提交于 2019-12-12 07:54:21
问题 I'm new to Knockout and I'm building an app that's effectively a large-scale calculator. So far I have two instances of knockout running on one page. One instance is working perfectly fine, however the other one is entirely broken and just won't seem to register at all? Below is my Javascript, fetchYear is the function that works perfectly fine and fetchPopulation is the one that's completely broken. It doesn't seem to register "ageview" from the HTML at all and I can't figure out. The error:

Knockout.js using `value:` binding in a `foreach` over a list of strings - does not update

天大地大妈咪最大 提交于 2019-12-12 07:48:59
问题 Here is a jsFiddle demonstrating the following problem: Given a foreach binding over a list of (observable) strings, the observables do not seem to update from changes to input tags bound inside the foreach. One would expect them to. Here's the example from the jsFiddle: HTML <ul data-bind='foreach: list'> <li><input data-bind='value: $data'/></li> </ul> <ul data-bind='foreach: list'> <li><span data-bind='text: $data'></span></li> </ul> Javascript ​var vm = { list: [ko.observable('123'), ko

How to can I create an array of knockout.js observables?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-12 04:18:11
问题 I have an array of objects for which I am showing their properties. How can add an individual edit functionality to them? Lets say it to be an edit button for each one of the elements of the list. I want to show input fields instead of text fields when the object is in edit mode, for this I am using the visible binding. So I need a Boolean observable for each of them. How can I do this without knowing the amount of elements in the list... I also have add and delete, so I would need to add

Controller Action won't bind JSON ViewModel

試著忘記壹切 提交于 2019-12-12 03:44:38
问题 Every time I post to my Action, my ViewModel is not null, but all the values inside always are. Where I have console.log , I can see perfect JSON being output to the console. Any ideas? Action: public ActionResult Add(MyViewModel model) { //stuff } JS: <script type="text/javascript"> var model = @Html.Raw(Viewbag.MyJSON); var viewModelDetails = ko.mapping.fromJS(model); this.addData = function() { var data = ko.toJSON(viewModelDetails); console.log(data); $.post("/user/add", data, function

How knockout ko.mapping.fromJs() handles the $ref nodes in Json

北城以北 提交于 2019-12-11 21:22:36
问题 The Json which came from the server contains some refs like this: [ { id:"1", name:"Mehran", supervisor: { id:"2", name: "Ayaz", supervisor: null } }, { id:"3", name:"Ramin", supervisor: {$ref="1"} } ] How does knockout mapping's fromJS or fromJson interpret this? 回答1: JSON in your example is invalid . It is unexpected token {$ref="1"} . Argument for fromJS function should be the valid JSON and argument for function fromJson should be a string representation of valid JSON value. Knockout will

Knockout JS binding and ajax taking longer to load

巧了我就是萌 提交于 2019-12-11 10:50:59
问题 I am trying to use below data for KO mapping I try to initialise it using ajax success event in document.ready var organisationData = data.d; var orgObject = { organisationsData: organisationData }; var newviewmodel = ko.viewmodel.fromModel(orgObject); The problem is ajax is taking much longer time to load and then the javascript error pops up saying the viewmodel doesnt exist. So How can I tell Knockout to rebind once the ajax has successfully loaded Is there anyway I can tell KO not to bind

Composing separate module instances in Durandal

对着背影说爱祢 提交于 2019-12-11 10:04:16
问题 I am composing the same form multiple times in the same module view but when I change the data in one field it reflects on every forms. Here is some cleaned up code. As you can see I made sure not to use the singleton pattern for the form I want to compose multiple times... view.html <button data-bind="click: append">Append</button> <div data-bind="foreach: odbcForms"> <div data-bind="compose: { model: $data, activationData: settings }"></div> </div> viewmodel.js define(['knockout', 'forms

Ability to update list without reloading it when editing a row using knockoutjs

时光总嘲笑我的痴心妄想 提交于 2019-12-11 07:03:52
问题 I have this code: http://jsfiddle.net/nickbuus/82q8j/11/ When I press edit on the "row" and then update I am updating the data on the server and then reloading all of the rows using: GetFoods('catname'); I am using knockoutjs - is there a clever way to connect and update the particular row in the list that was edited without having to reload all of the rows on update? 回答1: On the ApiController, you should add three new methods Create a new item Update existing item Get info of a specific item

Knockout.js: Unable to parse bindings from JSON

心已入冬 提交于 2019-12-11 03:46:53
问题 I have a view model that fetches JSON through AJAX, and creates a new Task, but Knockout keep giving me a binding error. If I hard code the data coming from the server straight in my view model, I don't receive any errors. My view model creates new task, that has an id, a question and a number of alteratives, which in itself has a text and correct boolean flag. The following code works perfectly fine: function Task(data) { var self = this; self.id = data.id; self.question = ko.observable(data

How to negate the isVisible binding in Knockout using a generic “not” binding?

守給你的承諾、 提交于 2019-12-11 03:09:51
问题 Is is possible to implement a "not" binding using Knockout? Basically, I want to negate the binding value, but retain the two-way binding/observability. In my view model, I have a property, isVisible , but my UI requirements dictate that I provide a checkbox to represent the hidden, or "not visible" state. I would prefer not to create a duplicate or second property to track the negated state. Code such as this does not work fully because it does not pass the observable to the binding: <label