knockout-mapping-plugin

Extending knockout viewmodels with prototype

廉价感情. 提交于 2019-12-24 11:10:50
问题 If a viewmodel is already defined, either manually or automatically with mapping plugin, is there any problem to "extend" (add properties/functions) the viewmodel later in the code by using prototype? I'm aware of the create callback of mapping plugin, I just want to know if there are any implications of using prototype instead? The reason I'm asking is because I'm generating large parts of the viewmodels from server side code, but sometimes need to extend the viewmodel later than at initial

JSON.NET class name as root

让人想犯罪 __ 提交于 2019-12-24 10:56:23
问题 I'm working with ASP.NET MVC4 WebApi and Knockout.js. My model consists of Pages that contain 1-N Controls . When I need to load a new Page , I will fetch the HTML View and the JSON serialized object and put all together with KO. As my model is very dynamic, I'm going to use the KO mapping plugin so I don't have to define all the observables. Here is my (very simplified) model: public class Page { public string Name { get; set; } public List<Control> Controls { get; set; } } public abstract

long ajax call breaking knockout binding

谁都会走 提交于 2019-12-24 07:31:35
问题 I am creating a personal website using durandal and knockout with the below code to bind a edit blog page. Everything worked great and I was able to bind the text area with the returned text of the ajax call. Once this was done I was curious if a long response from the webservice would break it, so I put in a Thread.Sleep(1000) into the service and now I cannot get it to bind the returned text to the text area. Any suggestions on how to get this to work??? side-note: I dont think this has to

Knockout radio button binding with boolean

那年仲夏 提交于 2019-12-23 02:39:14
问题 As per this Fiddle I created when you run it it does not bind the value to "no Blue" option as expected. var viewModel = { isBlue: ko.observable(false) //isBlue: ko.observable("false") this works }; As I have mentioned in there when I pass a string value "false" it does the binding. It's clear that knockout does type comparison as well. In my application I am using komapper which creates the view model. For properties in boolean it creates bool values and initialises variables in bool. Do I

Are computed observables on prototypes feasible in KnockoutJS?

╄→尐↘猪︶ㄣ 提交于 2019-12-22 05:25:12
问题 I have an array of items coming back from the service. I'm trying to define a computed observable for every Item instance, so my instinct tells me to put it on the prototype. One case for the computed observable: the system calculates points, but the user can choose to override the calculated value. I need to keep the calculated value available in case the user removes the override. I also need to coalesce user-assigned and calculated points, and add up the totals. I'm using mapping to do the

Using Knockout mapping for complex JSON

纵饮孤独 提交于 2019-12-21 20:55:44
问题 Most of Knockout seems very intuitive. One thing that is strange to me though is how the mapping plugin works. I was expecting/hoping I would be able to feed it JSON from an ajax call, and have a sort of "dynamic" view model that is available to reference in my HTML. The description of the mapping plugin even makes it sound like this is how it works: "If your data structures become more complex (e.g. they contain children or contain arrays) this becomes very cumbersome to handle manually.

KnockOut Mapping Hierarchical JS object

*爱你&永不变心* 提交于 2019-12-21 20:43:13
问题 I am trying to create view Models using KnockOut mapping plugin , This is the object , Basically below is a sentence with words in it. var data = { name: 'Example Title', sentences: [ {id: 1, words: [{text: 'word1'}, {text: 'word2'}]}, {id: 2, words: [{text: 'word3'}, {text: 'word4'}]} ]}; I would like to have three view Models , Article should contain sentences , an Sentence should contain words var ArticleViewModel = function(data) { var self = this; self.id = ko.observable(data.id); self

KnockOut Mapping Hierarchical JS object

空扰寡人 提交于 2019-12-21 20:41:52
问题 I am trying to create view Models using KnockOut mapping plugin , This is the object , Basically below is a sentence with words in it. var data = { name: 'Example Title', sentences: [ {id: 1, words: [{text: 'word1'}, {text: 'word2'}]}, {id: 2, words: [{text: 'word3'}, {text: 'word4'}]} ]}; I would like to have three view Models , Article should contain sentences , an Sentence should contain words var ArticleViewModel = function(data) { var self = this; self.id = ko.observable(data.id); self

KnockoutJS proper way to update observableArray AJAX

Deadly 提交于 2019-12-21 12:59:50
问题 In KnockoutJS, what's the proper way to update an observableArray of JSON data each time an AJAX command is run? Right now, I'm blanking the array using something like viewmodel.items([]), then repopulating it with the JSON data from the server. Short of using the KnockoutJS mapping plugin (which might be the only way to do this) what is the correct path? My server logic is going to send some of the same data each time, so I can't just iterate and push the items into the array unless I want

KnockoutJS proper way to update observableArray AJAX

痞子三分冷 提交于 2019-12-21 12:59:25
问题 In KnockoutJS, what's the proper way to update an observableArray of JSON data each time an AJAX command is run? Right now, I'm blanking the array using something like viewmodel.items([]), then repopulating it with the JSON data from the server. Short of using the KnockoutJS mapping plugin (which might be the only way to do this) what is the correct path? My server logic is going to send some of the same data each time, so I can't just iterate and push the items into the array unless I want