knockout-mapping-plugin

KO Mapping issue with child objects

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-10 03:39:44
问题 I get the following data from the server: var data = [{ id: 0, child: { prop1 : 'a', prop2 : 'b' } } //Child object has data ,{ id: 0, child: null } ]; // Child object is null I'm having some issues after I map the data using the knockout mapping plugin. The issue is that the inner child object is not of the same type. After executing this: ko.mapping.fromJS(data, viewModel.data); I get that the first object has a child property of type Object with the data. However the second object has a

KnockoutJS - Update ViewModel / Mapping Plugin

自古美人都是妖i 提交于 2019-12-09 09:32:20
问题 How can i update the complete viewModel ? On page load i get a Model and convert that using ko.mapping.fromJS(myObject) to a viewModel. If the user clicks a button i want to get updated data from the server Now i want to apply theese updates If i use ko.applyBindings(viewModel); it updates the ui perfectly. But it adds the same events again. So if the user clicks the button, the event gets fired twice, third and so on. Question What is a good way to update my complete viewModel. Maybe i

ko.mapping create function, extend object

谁都会走 提交于 2019-12-09 06:10:47
问题 Is it possible to modify the (for lack of a better term) schema of an object during the mapping process? I would imagine it is, I just can't seem to get it to work. I'm trying something like this: var data = { itemOne: 'someData', itemTwo: 'moreData' } var mapping = { "newItem": { create: function(options) { return ko.observable(false); } } }; ko.mapping.fromJS(data, mapping, _model.observableArrayPart); 回答1: Here is a sample that shows customizing how your array is creating and defining a

Knockout radio button binding with boolean

那年仲夏 提交于 2019-12-08 18:45:28
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 need to convert them to strings? In input radio button element we will always have to work with string

How can I change asp.net mvc's way of formatting JSON?

爱⌒轻易说出口 提交于 2019-12-08 12:07:01
问题 I have this model : public class Person { public string Name { get; set; } public int Age { get; set; } public List<Color> Colors { get; set; } } public class Color { public int ColorId { get; set; } public string Name { get; set; } } and asp.net MVC's return Json(...) gives me this: [{"Name":"JC","Age":24,"Colors":[{"ColorId":1,"Name":"Red"},{"ColorId":2,"Name":"Blue"}]}, {"Name":"Albert","Age":29,"Colors":[{"ColorId":2,"Name":"Blue"}]}] when I try to return a type of: List<Person> but I

Knockout and jQuery Validate

假装没事ソ 提交于 2019-12-08 08:00:08
问题 I've some problems getting KO and jQuery Validate plugin work together. My model: Parameter { int Id; string Name; decimal Price; } And my HTML+JS: <DOCTYPE html> <html> <head> <meta http-equiv='Content-Type' content='text/html;charset=utf-8'></meta> <script type='text/javascript' src='js/jquery-1.8.3.min.js'></script> <script type='text/javascript' src='js/jquery.validate.min.js'></script> <script type='text/javascript' src='js/knockout-2.2.0.js'></script> <script type='text/javascript' src=

KnockoutJS and binding a single object to a viewmodel

ⅰ亾dé卋堺 提交于 2019-12-08 06:42:44
问题 I've been round and round on this and don't see where things are going wrong. Maybe you can help please. There are multiple view models setup: var viewModels = { emailTemplateViewModel: { subject: new ko.observable('dd'), emailName: new ko.observable('dd'), emailAddress: new ko.observable('dd'), body: new ko.observable('dd') }, deviceSettingsViewModel: { managerName: new ko.observable('') } } ko.applyBindings(viewModels); And I'm trying to populate one of the view models with JSON returned

Initial selection on dropdowns with objects using KnockoutJS

こ雲淡風輕ζ 提交于 2019-12-08 02:45:17
问题 I have a model that looks something like this (not actual code so don't mind the possible mistyping). model = function(option, items) { self = this; self.options = options; self.items = ko.mapping.fromJS(items); } The options coantains list of objects that one can select from in a dropdown. The items also contains a list of object where each object has a identical object like one in the options-list. I then foreach over the items list and display an dropdown box on each row. I here need the

Knockout mapping and foreach data-bind on table with buttons, missing reference to viewmodel?

前提是你 提交于 2019-12-07 21:59:32
问题 I use mvc4 and entityframework in combination with knockout. I also use knockout mapping. But I run into a problem wich I cannot get solved. What I want to achieve: User clicks on delete button to delete row from table. [ Works ] Call the delete action method on the mvc controller to actualy delete the data from the database. [ Works ] Send back new Json object containing the data of the new changed table. [ Works ] Load the new data in my knockout viewmodel and update the UI using ko.mapping

knockout.js mapping causing infinite recursion on IE9

久未见 提交于 2019-12-07 12:07:27
I'm having endless recursion on IE by my knockout.js mapping. Can someone more familiar with KO to spot what am I doing wrong? I have following knockout.js mapping: var mapping = { create: function(options) { return new MyViewModel(options.data); }, 'ChildItems': { create: function(options) { return new ChildVM(options.data); } } } When I render the page approx. 1 time out of 5 IE ends up with following infinite recursion stack(causing "SCRIPT28: Out of stack space"). IE's callstack: fromJS MyViewModel create Anonymous Function withProxyDependentObservable createCallback updateViewModel fromJS