knockout-mapping-plugin

Knockout Mapping Validation

淺唱寂寞╮ 提交于 2019-11-30 03:12:38
I'm trying to attach validation to a mapped view. I'm using Knockout Mapping and Validation plugins. Pseudo-models: Person { int Id; string Name; Book[] Books; } Book { int Id; string Name; } Javascript: function viewModel() { var self = this; self.persons = ko.observableArray(); // persons are retrieved via AJAX... ko.mapping.fromJS(persons, {}, self.persons); } jQuery(function( $ ) { ko.applyBindings(new viewModel()); }); How can I extend persons observableArray to set validation rules and message? I need to validate both persons and books sub-array properties. I've found only examples that

Knockout JS ObservableArray with many-to-many relationships

和自甴很熟 提交于 2019-11-29 22:40:32
问题 I am creating a guest list app using Knockout.js, and so far things are going swimmingly. However I have a best-practices question. My app has several different types of objects: guests and tags among them. Guests can have multiple tags, and tags can have multiple guests. At different points in the app, I need to display both arrays individually. For example, I have a "Guests" view where one can see all the guests along with their associated tags, and I also have a "Tags" view where one can

Knockoutjs select with option group

拥有回忆 提交于 2019-11-29 05:33:53
Is there any way in Knockoutjs binding where I can specify optionsGroup ? something like follwoing <select data-bind="options: collection, optionsText: 'Text', optionsGroup: 'Group'/> Please do reply. I got the answer of the same, here is the answer if anybody wants, <td><select class="fieldValue" data-bind="foreach: $root.AvailableFields, value: FieldId, event :{ change: $root.onFieldSelectionChange}"> <optgroup data-bind="attr: {label: FieldGroupName}, foreach: Fields"> <option data-bind="text: HeaderText, value: FieldId"></option> </optgroup> </select> </td> In many cases, you don't need

Knockout Mapping Validation

╄→尐↘猪︶ㄣ 提交于 2019-11-29 00:51:40
问题 I'm trying to attach validation to a mapped view. I'm using Knockout Mapping and Validation plugins. Pseudo-models: Person { int Id; string Name; Book[] Books; } Book { int Id; string Name; } Javascript: function viewModel() { var self = this; self.persons = ko.observableArray(); // persons are retrieved via AJAX... ko.mapping.fromJS(persons, {}, self.persons); } jQuery(function( $ ) { ko.applyBindings(new viewModel()); }); How can I extend persons observableArray to set validation rules and

Am I overusing the Knockout mapping plugin by always using it to do my viewmodel?

梦想的初衷 提交于 2019-11-28 13:58:34
问题 I'm still learning the proper usage of Knockout and I've found myself quickly getting away from ever typing ko.observable when setting up my viewmodel and instead just defining an object literal and passing it through the mapping plugin with something like var viewModel = ko.mapping.fromJS(data); or at the very least, something along the lines of stuffing all of my data into an attribute on the viewModel like so var viewModel = { ... events etc ... , "data": ko.mapping.fromJS(data) } To be

Using ScriptSharp with Knockout.Mapping through RequireJS

佐手、 提交于 2019-11-28 10:53:43
问题 I'm struggling with all the Script# Dependency loading. I have a Script# Project referencing the knockout library. Which I got to work after some time with RequireJS. Now I'd like to use KnockoutJS mapping which complies to something like var model = ko.mapping.fromJS(data, {}, new ViewModel()); However ko.mapping is undefined. If I manually (for testing only) change the compiled .js file to include mapping like this: define('MyApp', ['ss', 'jquery', 'knockout', knockout.mapping], function

Knockout.js mapping plugin with require.js

流过昼夜 提交于 2019-11-28 07:33:33
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:{ exports: '_' }, knockout:{ deps: ["jquery"], exports: "knockout" } } } In my view model define([

Mapping deeply hierarchical objects to custom classes using knockout mapping plugin

▼魔方 西西 提交于 2019-11-28 03:51: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 which has a child myCustomerPerson object !! containing "Son of Graham" and that child object contains a

Knockout.js Make every nested object an Observable

守給你的承諾、 提交于 2019-11-27 18:31:08
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 that i can set a computed observable on details and get noticed as soon as any of the internal data

Knockout JS mapping plugin without initial data / empty form

最后都变了- 提交于 2019-11-27 12:10:15
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. Without this initial data, the mapping plugin can't 'generate' the viewmodel (ko.mapping.fromJS). This