knockout-mapping-plugin

Mapping deeply hierarchical objects to custom classes using knockout mapping plugin

北战南征 提交于 2019-11-27 05:13:09
问题 Using the knockout mapping plugin ( http://knockoutjs.com/documentation/plugins-mapping.html ) can you map a deeply hierachical object? If I have an object with multiple levels: var data = { name: 'Graham', children: [ { name: 'Son of Graham', children: [ { name: 'Son of Son of Graham', children: [ { ... and on and on.... } ] } ] } ] } How do I map it to my custom classes in javascript: var mapping = { !! your genius solution goes here !! !! need to create a myCustomPerson object for Graham

Knockout.js mapping plugin with require.js

无人久伴 提交于 2019-11-27 01:51:34
问题 What is the standard way of loading mapping plugin in require.js ? Below is my config.js (require.js config file) require.config({ // Initialize the application with the main application file. deps: ["app"], paths:{ // JavaScript folders. libs: "lib", plugins: "lib/plugin", templates: "../templates", // Libraries. jquery: "lib/jquery-1.7.2.min", underscore: "lib/lodash", text: 'text', order: 'order', knockout: "lib/knockout", knockoutmapping: "lib/plugin/knockout-mapping" }, shim:{ underscore

Map JSON data to Knockout observableArray with specific view model type

旧巷老猫 提交于 2019-11-26 23:33:25
Is there a way to map a JSON data object to an observable array and then in turn have each item of the observable array be initialized into a specific type of view model? I've looked at all of knockout's documentation along with the knockout and mapping examples here and I can't find any answer that works for what I'm after. So, I have the following JSON data: var data = { state : { name : 'SD', cities : [{ name : 'Sioux Falls', streets : [{ number : 1 }, { number : 3 }] }, { name : 'Rapid City', streets : [{ number : 2 }, { number : 4 }] }] } }; And I have the following view models: var

Knockout.js Make every nested object an Observable

不羁的心 提交于 2019-11-26 19:28:36
问题 I am using Knockout.js as a MVVM library to bind my data to some pages. I'm currently building a library to make REST calls to a web service. My RESTful web service returns a simple structure: { id : 1, details: { name: "Johnny", surname: "Boy" } } I have an observable main parent, myObject . When I do myObject(ko.mapping.fromJS(data)) the observables in myObject are: id name surname How can I make details (and theoretically any object in the structure an observable)? I need this behavior so

KnockOutJS - Multiple ViewModels in a single View

好久不见. 提交于 2019-11-26 19:18:09
I'm thinking that my application is getting quite large now, too large to handle each View with a single ViewModel. So I'm wondering how difficult it would be to create multiple ViewModels and load them all into a single View. With a note that I also need to be able to pass X ViewModel data into Y ViewModel data so the individual ViewModels need to be able to communicate with each other or at least be aware of each other. For instance I have a <select> drop down, that select drop down has a selected state which allows me to pass the ID of the selected item in the <select> to another Ajax call

Knockout JS mapping plugin without initial data / empty form

只愿长相守 提交于 2019-11-26 15:57:58
问题 We are using knockout and the knockout mapping plugin to facilitate databinding in our jQTouch web application. The reason we use the mapping plugin, is to be able to use knockout without the need to define/change viewmodels manually in javascript. The mapping plugin works great when you have an initial load of data from the server/client side database. The problem we are having is that we have some screens/views which have a form in which it is possible that there isn't any initial data.

Map JSON data to Knockout observableArray with specific view model type

你离开我真会死。 提交于 2019-11-26 12:20:53
问题 Is there a way to map a JSON data object to an observable array and then in turn have each item of the observable array be initialized into a specific type of view model? I\'ve looked at all of knockout\'s documentation along with the knockout and mapping examples here and I can\'t find any answer that works for what I\'m after. So, I have the following JSON data: var data = { state : { name : \'SD\', cities : [{ name : \'Sioux Falls\', streets : [{ number : 1 }, { number : 3 }] }, { name : \

KnockOutJS - Multiple ViewModels in a single View

我怕爱的太早我们不能终老 提交于 2019-11-26 06:54:25
问题 I\'m thinking that my application is getting quite large now, too large to handle each View with a single ViewModel. So I\'m wondering how difficult it would be to create multiple ViewModels and load them all into a single View. With a note that I also need to be able to pass X ViewModel data into Y ViewModel data so the individual ViewModels need to be able to communicate with each other or at least be aware of each other. For instance I have a <select> drop down, that select drop down has a