knockout-mapping-plugin

knockout.js save form to json

ぐ巨炮叔叔 提交于 2019-12-11 03:43:43
问题 I have my form mapped using knockout.js and mapping plugin. I am ready to save the form to json and send it back to the server. This is my first time doing this so what is the simplest way to do it? Here is what I have so far: // Here's my data model var viewModel; $.getJSON('/myJSONdata', function (data) { viewModel = ko.mapping.fromJS(data); ko.applyBindings(viewModel); }); //convert mapped data to json format var jsonData = ko.mapping.toJSON(viewModel); // Do something to send the form

How to add parent function to KnockOut double-nested mapping?

眉间皱痕 提交于 2019-12-11 03:09:20
问题 I'm using KnockOut mapping fromJS to create my View Model from a JSON object like the following: { "cats": [{ "name": "fluffy", "color": "brown", "kittens": [{ "name": "spot", "color": "brown" }, { "name": "rascal", "color": "grey" }, { "name": "trouble", "color": "white" }] }, { "name": "kitty", "color": "red", "kittens": [{ "name": "lady", "color": "red" }, { "name": "skat", "color": "striped" }] }] } html: <div data-bind="foreach:cats"> <span data-bind="text:name"></span> <table> <tr data

Option text becomes a function string after updated with fromJS

假如想象 提交于 2019-12-11 03:02:49
问题 Why does the option text get converted to a string of a function after the values has been updated from ko.mapping.fromJS? Sample: http://jsfiddle.net/tYnc6/24/ Html: <div> <select data-bind="options: items, value: selected, optionsText: function(item) { return ('[' + item.Id + '] ' + item.Name) }, optionsCaption: 'Choose...'"></select> <button data-bind="click: update">Update</button> </div> ​ Javascript: var mapping = { key: function(data) { return ko.utils.unwrapObservable(data.Id); } };

Updating Sub Properties in Knockout JS mapping plugin

蹲街弑〆低调 提交于 2019-12-11 02:58:57
问题 I'm having an issue with knockout js and mapping plugin with a hierarchical view model My viewmodel is structured somewhat like this: VM = { members:[ { name:"name 1", volunteering:[{...},{...},{...}] }, { name:"name 1", volunteering:[{...},{...},{...}] } ] } Each member is in a tab, and each tab has a grid of volunteering activities. Clicking on an item in the grid pops up a dialog box to edit the volunteering activity. At this point I clone the object to facilitate 'cancel edit'

How to define function inside knockout viewmodel that is filled with Json data

旧巷老猫 提交于 2019-12-11 01:55:39
问题 I am having issues with defining a function inside my viewmodel. I fetch json data via jquery getJSON and map this data to my viewmodel. $.getJSON('/Company/GetCompanies', function(data) { var viewModel = new CompanyViewModel() viewModel.model = ko.mapping.fromJS(data) ko.applyBindings(viewModel) }); Below is my viewmodel. As you can see what I want to do is, returning one of the properties of viewmodel via function called companyName var CompanyViewModel = function() { var self = this; self

knockout.mapping & Require.js bug

孤街浪徒 提交于 2019-12-11 01:28:49
问题 So I am trying to integrate knockout.mapping.js with require.js. I have tried following this example. Unfortunately, I keep on getting this error: GET http://[url]/Scripts/app/contractor/ko.js 404 (Not Found) Uncaught Error: Script error for: ko I have set up following files: app.index.js requirejs.config({ "baseUrl": "../Scripts/app/contractor", "paths": { "app.index": "app.index", "knockout": "//cdnjs.cloudflare.com/ajax/libs/knockout/2.2.1/knockout-min", "mapping": "//cdnjs.cloudflare.com

Performing partial updates with KnockoutJS mapping plugin

随声附和 提交于 2019-12-10 13:37:25
问题 Right now, I'm using this JSON with the KO Mapping plugin and it's working fine: { "Controls": [ { "Fields": [ { "Name": "emailField", "Text": "email", "Visible": true }, { "Name": "hiddenField", "Text": "text", "Visible": true } ], "Name": "form2", "Type": "Form" }, { "Data": [ [ "Federico Aloi", 20 ], [ "Andres Lopez", 31 ], [ "Pablo Perez", 32 ] ], "Fields": [ { "Name": "nameField", "Text": "Nombre", "Visible": true }, { "Name": "ageField", "Text": "Edad", "Visible": true } ], "Name":

Knockout Mapping re-rendering everything

ぐ巨炮叔叔 提交于 2019-12-10 11:56:17
问题 I'm using the Knockout mapping plug-in to refresh the UI with JSON retrieved from the server every 3 seconds. The UI consists of some nested foreach bindings. However, it seems that everything in all the foreach bindings are getting completely deleted and re-rendered with every refresh, even when nothing has changed. var testData = { Answers: [], Inspectable: { Categories: [{ Id: 1, Name: "Test Category", Questions: [{ Id: 1, Text: "Test Question", Active: true, Answers: [{ Text: "Test Answer

Knockout JS Observable array data group total age count per section

半世苍凉 提交于 2019-12-10 11:49:49
问题 I have an observable array var myArray = ko.observableArray([ { name: "Jimmy", type: "Friend", Age: 30 }, { name: "George", type: "Friend", Age: 40 }, { name: "Zippy", type: "Enemy", Age: 20 } ]); Now I want my output as Friend Total Age: 70 Jimmy 30 George 40 Enemy Total Age : 20 Zippy 20 There is a similar jsfiddle link 回答1: If you want to keep with the generic structure (not just create computeds directly for "FriendTotalAge" and "EnemyTotalAge"), then you could expand the distinct

How do I customize knockout mapping creation in nested model?

僤鯓⒐⒋嵵緔 提交于 2019-12-10 11:26:18
问题 Completely new to Knockout and I am trying to map a JSON response from the server to specific models using the knockout mapping plugin. The models are nested and I'm trying to override object construction using the create callback even in the nested models. However, it doesn't appear that my mapping options are being read properly. Example JSON: { "EmployeeFeedbackRequestSubmissions": [ { "EmployeeFeedbackRequestSubmissionId": 0, "Employee": "John Smith0", "EmployeesWorkedWith": [ {