knockout-mapping-plugin

Knockout.js mapping plugin with require.js

主宰稳场 提交于 2019-12-11 22:46:10
问题 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

How knockout ko.mapping.fromJs() handles the $ref nodes in Json

北城以北 提交于 2019-12-11 21:22:36
问题 The Json which came from the server contains some refs like this: [ { id:"1", name:"Mehran", supervisor: { id:"2", name: "Ayaz", supervisor: null } }, { id:"3", name:"Ramin", supervisor: {$ref="1"} } ] How does knockout mapping's fromJS or fromJson interpret this? 回答1: JSON in your example is invalid . It is unexpected token {$ref="1"} . Argument for fromJS function should be the valid JSON and argument for function fromJson should be a string representation of valid JSON value. Knockout will

Using KnockoutJS automatic binding

情到浓时终转凉″ 提交于 2019-12-11 18:59:37
问题 I am trying to bind a List=>List=>List=>List object into a Knockout JS view model. My data from $getJSON is as follows I tried the mapping plugin to create a viewmodel like :- var viewModel = ko.mapping.fromJS(d.organisationsData); and the problem is I dont know why (/whether) mapping is happening properly. I am unable to use data-bind to iterate over this List and innerList properties This is my ViewModel object I tried iterating using data-bind: for-each ListOfOrg and it is showing Binding

Extending dynamic and mapped data in Knockout

为君一笑 提交于 2019-12-11 09:50:09
问题 Using Knockout.JS, I'm trying to determine how to best extend objects in the view model when they will be both loaded via the mapping plugin and dynamically added. In this example, I'm adding a method addChild to the Person object. Extending during mapping: var myPersonModel = function (data) { ko.mapping.fromJS(data, {}, this); this.addChild = function () { this.children.push(new Child()); } .bind(this); } var mapping = { 'people': { create: function (options) { return new myPersonModel

Set the binding of a dropdown in knockout to an object

狂风中的少年 提交于 2019-12-11 09:33:14
问题 I am trying to trying to set a the binding a drop down list (kendo drop down) uses to a full object. I am using Knockout-Kendo to accomplish the binding but I don't think the kendo stuff or knockout-kendo stuff is a factor in my problem. For example I have the following object var model = { "Client": null, "Clients": [ { "CompanyAccount": { "RelationshipManager": {}, "CompanyAccountId": 1, "Name": "My Company Name", "PhoneNumber": "(555) 555-5555", "Address": { "State": { "StateId": 6, "Name"

Knockout Mapping reading JSON

ε祈祈猫儿з 提交于 2019-12-11 08:47:04
问题 Just starting with KnockOut Mapping to read some JSON (using Google Books API) , but can't seem to get it to work. No errors report, but nothing is displayed. Probably a simple issue I overlooked, but thanks for the review. Markup.... <body> <h2>Find Cat in the Hat</h2> <div> <input id="booksearch" /> </div> <div> <table> <thead> <tr> <th>Volumes</th> </tr> </thead> <tbody data-bind="foreach: model.items"> <tr> <td data-bind="text: model.id"></td> </tr> </tbody> </table> </div> <input id=

knockout draggable sortable mapping clone alteration

巧了我就是萌 提交于 2019-12-11 07:14:42
问题 I am trying to use knockout-sortable, with the mapping plugin, to drag a list of products to another list. Here is a very stripped-back fiddle to try and show what I'm getting at. What I want is for the products in the 'cart' to reference, not clone, the products on the 'shelf'. I have managed to calculate the name of the items in the cart by referencing those on the shelf, but I am having trouble in getting the products in the cart to only have the data they need to make this reference,

Is it possible to iterate through mapped observable array and subscribe?

廉价感情. 提交于 2019-12-11 05:07:03
问题 I'm using the knockout mapping plugin to map a collection of objects from the server to an observable array. I'd like to be able to subscribe to some change events on a few properties on those mapped objects. Can anyone point out what I'm doing wrong? $.getJSON(apiUrl, function (data) { ko.mapping.fromJS(data, {}, self.ReportTemplates); for (var i = 0; i < self.ReportTemplates().length; i++) { var reportTemplate = self.ReportTemplates()[i]; //try to subscriber here? reportTemplate.VideoId

Binding list of objects with Knockoutjs

自闭症网瘾萝莉.ら 提交于 2019-12-11 04:53:51
问题 I'm trying to bind data to ASP.NET Webforms Application using KnockoutJS and Knockout Mapping HTML <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script> <script src="Scripts/knockout-2.3.0.js" type="text/javascript"></script> <script src="Scripts/knockout.mapping-latest.js" type="text/javascript"></script> <script type="text/javascript"> function bindModel(data) { var viewModel; viewModel = ko.mapping.fromJS(data); console.log(viewModel); ko.applyBindings(viewModel); } $

beforeChange value is undefined in Knockout when using the mapping plugin

 ̄綄美尐妖づ 提交于 2019-12-11 04:36:22
问题 Based on the answer of this question, I try to get the value before change in an observable with the following code. var phoneBook; function debug(s) { $("#log").append('<br>' + s); } function PhoneNumber(data) { var self = this; self.phoneType = ko.observable(); self.phoneNumber = ko.observable(); self.phoneNumber.subscribe(function(newValue) { debug('newvalue: ' + newValue); }); self.phoneNumber.subscribe(function(previousValue) { debug(previousValue); }, self, "beforeChange"); ko.mapping