knockout-mapping-plugin

Knockout's mapping breaks observable arrays

一笑奈何 提交于 2019-12-07 08:23:49
问题 I'm experiencing a strange problem with Knockout's mapping plug-in. If I fill an observable array through mapping I can't iterate the array or get its length, even though the UI is updated correctly, the array seems empty. You can find a working jsFiddle here: http://jsfiddle.net/VsbsC/ This is the HTML mark-up: <p><input data-bind="click: load" type="button" value="Load" /></p> <p><input data-bind="click: check" type="button" value="Check" /></p> <table> <tbody data-bind="foreach: items">

Turn certain observableArray objects properties into observable

放肆的年华 提交于 2019-12-07 06:36:51
问题 Say I have this array of same-type objects: var people = [ { status: 0, name: "name1"}, { status: 1, name: "name2"} ]; and I want it not only to be observableArray, but also I want to observe ONLY, say, status property of each object. Imagine that the objects themselves might be added or deleted. The name property of any of those objects is not going to change so I don't really need to observe the name but the status of every object might get changed, thus it'd be cool to make it observable.

how to add new item using knockout mapping plugin

对着背影说爱祢 提交于 2019-12-07 06:09:03
问题 I'm trying out a knockout mapping sample and think I'm almost there. I don't seem able to add a new Foo to the viewModel.foos - can anyone see what I've missed here? var Foo = function (data) { var self = this; self.id = data.id; self.Name = ko.observable(data.Name); } var dataMappingOptions = { key: function(data) { return data.id; }, create: function (options) { return new Foo(options.data); } }; var viewModel = { foos: ko.mapping.fromJS([]), loadInitialData: function () { ko.mapping.fromJS

Signalr deserializes my objects incorrectly in IIS 7.5 and Edge/IE, foreverFrame broken?

大兔子大兔子 提交于 2019-12-07 03:02:29
问题 So I have a simple Signalr/Knockout project that uses the mapping plugin to bind a simple object (item with an array of more items) to viewModels I defined in JS: var someObjectMapping = { 'MyItemArray': { create: function (options) { return new MyItemViewModel(options.data); } } } var myItemMapping = { 'ItemChildren': { create: function (options) { return new ItemChildViewModel(options.data); } } } var SomeObjectViewModel = function (data) { ko.mapping.fromJS(data, someObjectMapping, this);

KnockoutJS and binding a single object to a viewmodel

那年仲夏 提交于 2019-12-06 23:12:33
I've been round and round on this and don't see where things are going wrong. Maybe you can help please. There are multiple view models setup: var viewModels = { emailTemplateViewModel: { subject: new ko.observable('dd'), emailName: new ko.observable('dd'), emailAddress: new ko.observable('dd'), body: new ko.observable('dd') }, deviceSettingsViewModel: { managerName: new ko.observable('') } } ko.applyBindings(viewModels); And I'm trying to populate one of the view models with JSON returned from the server (this is correct and properly formatted). function LoadEmailTemplate() { $.getJSON('

Knockout mapping and foreach data-bind on table with buttons, missing reference to viewmodel?

为君一笑 提交于 2019-12-06 14:19:27
I use mvc4 and entityframework in combination with knockout. I also use knockout mapping. But I run into a problem wich I cannot get solved. What I want to achieve: User clicks on delete button to delete row from table. [ Works ] Call the delete action method on the mvc controller to actualy delete the data from the database. [ Works ] Send back new Json object containing the data of the new changed table. [ Works ] Load the new data in my knockout viewmodel and update the UI using ko.mapping.fromJS() and ko.applyBindings() [Does not work and I am realy lost here ] It looks like I totaly lost

Knockout isDirty example, using dynamic viewmodule from mapping plugin

给你一囗甜甜゛ 提交于 2019-12-06 12:33:36
I'm using Ryan Niemeyer's Dirty Flag . An example of his method can be seen in this jsFiddle . He has a dirtyItems method on the ViewModel this.dirtyItems = ko.computed(function() { return ko.utils.arrayFilter(this.items(), function(item) { return item.dirtyFlag.isDirty(); }); }, this); However, I can't seem to get his dirtyItems method working with my data.The biggest difference is that I am using the mapping plugin. Everything I have tried comes back empty. Here is a jsFiddle of my implementation. You could add the dirtyFlag to the ProfilePropertyValue like: var mappingOptions = {

How do I customize knockout mapping creation in nested model?

半腔热情 提交于 2019-12-06 09:26:51
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": [ { "EmployeeName": "Joe Smith", "ProjectsWorked": [ { "ProjectName": "Document Management Console" }, {

Initial selection on dropdowns with objects using KnockoutJS

被刻印的时光 ゝ 提交于 2019-12-06 06:31:59
I have a model that looks something like this (not actual code so don't mind the possible mistyping). model = function(option, items) { self = this; self.options = options; self.items = ko.mapping.fromJS(items); } The options coantains list of objects that one can select from in a dropdown. The items also contains a list of object where each object has a identical object like one in the options-list. I then foreach over the items list and display an dropdown box on each row. I here need the object in the current items from the items list to be the selected option . When I however don't set an

Throttling with knockout mapping plug

懵懂的女人 提交于 2019-12-06 02:09:25
I'm having a problem with the knockout-mapping plugin with IE8. Our situation is that we send over all the possible records that can be displayed to the client. Then we handle all paging and filtering on the client side for a responsive system. Currently, we are sending of a list of 250 records to display in a jQuery template based grid via jQuery ajax. When we call ko.mapping.fromJS (not the fromJSON function) to map the objects, we are getting a "Script taking too long" message from IE8. Doesn't occur in FF and Chrome as their java script executes much faster. Is there a straight forward way