knockout-mapping-plugin

Delete Item from List using Knockout.js

早过忘川 提交于 2019-12-21 05:15:26
问题 I am trying to delete an item from a list. I am using knockout.js with the mapping plugin. My code looks like this: Serialize to Json @{ var jsonData = new HtmlString(new JavaScriptSerializer().Serialize(Model));} Template <script type="text/html" id="imgsList"> {{each model.Imgs}} <div style="float:left; margin: 10px 10px 10px 0;"> <div><a href="${Filename}"><img src="${Filename}" style="width:100px;"></img></a></div> <div data-bind="click: deleteImage">Delete</div> </div> {{/each}} </script

KnockoutJS: Adding Observable Properties and Functions to objects in a mapping generated ObservableArray

人盡茶涼 提交于 2019-12-20 10:28:26
问题 I'm new to KnockoutJS, and I'm stuck trying to add additional properties and methods to the generated objects in the ko.observableArray() as created by the mapping plugin. Here's where I'm up to: I have a JSON array of Users I've created the ko.observableArray() with the mapping plugin I've got a template that creates table row for each User , so far so good :o) Here's what I'm trying to do: Each User has a property called 'IsActive' - I'd like to data-bind a click event to a method on each

Knockout JS mapping plugin confusion

六月ゝ 毕业季﹏ 提交于 2019-12-20 03:43:24
问题 I'm confused as to when and where I should declare my viewModel when using the mapping plugin. Here's my json file: { "members": [ { "memberid": "001", "membername": "Jason" }, { "memberid": "002", "membername": "Bob" } ] } Here's the html template: <div data-bind="foreach: members"> <h3 data-bind="text: memberid"></h3> <p>Name: <span data-bind="text: membername"></span></p> </div> Here is the rest: var data = $.getJSON("members.json",function(data) { var viewModel = ko.mapping.fromJSON(data)

knockout mapping with computed fields

旧街凉风 提交于 2019-12-18 12:37:05
问题 I'm getting data from a WCF service,and i map, and bind the data with my DOM object : var PayinyVM = {}; $.getJSON('/service/PaidService.svc/PaidList', function (data) { var tmp = JSON.stringify(data.d); PayinyVM.model = ko.mapping.fromJSON(tmp); ko.applyBindings(PayinyVM); }); the result is shown as excepted on my DOM bind it to model. What I couldn't find out is how to add some computed observable let's say my data is returning people with FirstName and LastName, how can I make a computed

Trying to map array from JSON to knockout using mappings

故事扮演 提交于 2019-12-14 03:10:46
问题 Hi I have a JSON array like so [{ "id": "537901a53513fa3374bec718", "images": [], "itemImage": "img/3.jpg", "createdDate": "5/18/2014 6:53:25 PM", "location": [ -2.057802, 52.609711 ] }, { "id": "537901a53513fa3374bec710", "images": [ "img/17.jpg" ], "itemImage": "img/1.jpg", "createdDate": "5/18/2014 6:53:25 PM", "location": [ -2.062251, 52.612397 ] }] I'm trying to use the ko.mapping.fromJSON / JS, but i keep messing up sigh :( var viewModel = {}; in my Ajax success function, viewModel

Why won't my submit from Knockout bind to my MVC Model

廉价感情. 提交于 2019-12-14 00:34:59
问题 I have a knockout model that is feeding my page and on a save the following code is executed client side. self.save = function() { var tirerun = ko.mapping.toJSON(self.data()); $.ajax({ type: 'post', url: "@Url.Action("SaveTireRunModel", "Events")", data: tirerun, success: function(result) { if (!result.success) { alert(result.error); } else {} } }); }; It then posts the following JSON to my server (From fiddler and cropped for brevity) With the following http request header POST http:/

Knockout.js and mapping plugin not deep translating

99封情书 提交于 2019-12-13 20:23:51
问题 I use a json object to handle my menus and breadcrumbs. Now below you can see that the first two "Navigation" nodes are observable, but the last one isn't. It is just a regular array for some reason. Does the mapping plugin not deep clone the object? Firebug output: app.viewModel.members.layout().Navigation()[2].Navigation()[1].Navigation() <-- errors Initialization: app.viewModel.members.layout(ko.mapping.fromJS(json.Layout)); json.Layout JSON: { "Layout": { "Navigation": [ { "ID":

Mapping JSON with knockout fails to populate type defined object properties

北城余情 提交于 2019-12-13 18:34:09
问题 I'm trying to map JSON data using the knockout.mapping plugin, however the heirarcical JSON data fails to populate my object properties correctly, the top level loads fine but not the child 'RootTarget' data? What am I doing wrong? Knockout Javascript var Query = function(json) { this.ID = ko.observable(0); this.Name = ko.observable(); this.RootTargetID = ko.observable(); this.RootTarget = ko.observable(); var mapping = { 'RootTarget': { create: function (args) { return new QueryTarget(args

Automate mapping of dependent properties in knockout

送分小仙女□ 提交于 2019-12-13 07:23:42
问题 I have a list of product options each with an sku identifier that is received as JSON from the server. I then have other options which depend on prerequisite values being selected, this is defined by the requires array property of the product-option arrays: var serverOptions = [{ name: "DELL R210", price: 100, sku: 1001, },{ name: "DELL R710", price: 200, sku: 1002, },{ name: "DELL R720 Dual CPU", price: 300, sku: 1003, }]; var osOptions = [{ name: "Windows Standard", sku: "201", price: 1, },

toJSON view model overrides not being reflected after Knockout unmapping

笑着哭i 提交于 2019-12-13 04:29:10
问题 I have a deep object graph from the server which I am representing with a Knockout view model structure which omits various unnecessary properties at each level but preserves the basic hierarchy. I'm using the Knockout mapping plugin in both directions. At each view model level below the root, the "constructor" of the current view model accepts its parent view model to keep as a reference, plus the part of the original data necessary to construct itself with. It then creates a new set of