knockout-mapping-plugin

knockout.js mapping causing infinite recursion on IE9

你离开我真会死。 提交于 2020-01-03 02:28:08
问题 I'm having endless recursion on IE by my knockout.js mapping. Can someone more familiar with KO to spot what am I doing wrong? I have following knockout.js mapping: var mapping = { create: function(options) { return new MyViewModel(options.data); }, 'ChildItems': { create: function(options) { return new ChildVM(options.data); } } } When I render the page approx. 1 time out of 5 IE ends up with following infinite recursion stack(causing "SCRIPT28: Out of stack space"). IE's callstack: fromJS

Throttling with knockout mapping plug

你离开我真会死。 提交于 2020-01-02 07:24:06
问题 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.

Knockout DateTime Picker - Default Date not Binding

烈酒焚心 提交于 2020-01-01 14:24:36
问题 I am using this Bootstrap DateTime Picker: http://eonasdan.github.io/bootstrap-datetimepicker/ I have created a Custom Binder for DateTime called datepicker: ko.bindingHandlers.datepicker = { init: function(element, valueAccessor, allBindingsAccessor) { //initialize datepicker with some optional options var options = allBindingsAccessor().datepickerOptions || {format: 'DD/MM/YYYY HH:mm'}; $(element).datetimepicker(options); //when a user changes the date, update the view model ko.utils

Best way to get only modified rows from observableArray (when there is bulk edit option)

独自空忆成欢 提交于 2020-01-01 05:50:15
问题 I have an ObservableArray collection which binds to the HTML table with bulk edit option (MVC3), every time the user hits commit I wanted to send only the modified rows from the collection instead of sending entire viewmodel list, please advise if any best way to track or filter only the modified rows. 回答1: Here is a post about creating a dirty flag in Knockout that will track changes to all observables in an object. Typically, you would add a dirty flag to each item in your array in a

Edit item in knockout observableArray

拟墨画扇 提交于 2019-12-31 03:42:07
问题 I am looking for an example where i can show an observableArray as normal text with edit / delete links. Items can be added/edited from a separate form. I am not able to edit the record from edit link it add new record! self.editItem = function (p) { //edit code ////??????? }; Here is example 回答1: As other mentioned in there answers, you should use with binding for editing any particular record. Here i have created a demonstration according to your need. http://jsfiddle.net/85afB/1/ 回答2: You

Knockoutjs select with option group

落花浮王杯 提交于 2019-12-29 06:43:05
问题 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. 回答1: 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

knockout recursive mapping issue

风流意气都作罢 提交于 2019-12-25 05:03:26
问题 this post is a follow-up to this one. I've updated the code as followed: viewModel.getQuotesSuccess = function (result) { var myCoverQuotesViewModel = function (data) { var self = this; ko.mapping.fromJS(data, {}, self); self.Childs = ko.observableArray(ko.utils.arrayMap(data.Childs, function (c) { return new myCoverQuotesViewModel(c); })); self.selectedChild = ko.observable(); self.showChildren = ko.computed(function () { return self.selectedChild() && self.selectedChild().Childs().length >

How can I create a typed collection class in Knockout mapping?

混江龙づ霸主 提交于 2019-12-25 00:09:07
问题 I'm using knockout with the mapping plugin so that I can write code like this: function ContactViewModel() { //other properties... this.emails = ko.observableArray(); } function ContactEmailViewModel() { //other properties... this.address = ko.observable(); } var koContactMap = { 'emails': { create: function (options) { return new ContactEmailViewModel(options.data); } } }; var model = new ContactViewModel(); ko.mapping.fromJS([JSON data from web service], koContactMap, model); In English, I

KnockoutJS Mapping Plugin (observableArray)

可紊 提交于 2019-12-24 14:18:03
问题 I am new to knockout and I am having a problem with using the mapping plugin as I do not understand how it maps my JSON data. This is a sample json data similar to what is in my program: contact: { name : 'John', email : 'address@domain.com', phones : [{ phoneType : 'Home Phone', phoneNumber: '999-888-777'}, { phoneType : 'Business Phone', phoneNumber: '444-888-777'}, }] } As you can see, this json data contains an array of phones. I used knockout mapping plugin and I can bind the 'name',

Knockout mapping how to add and update

﹥>﹥吖頭↗ 提交于 2019-12-24 11:32:05
问题 I have a js object that looks like the following {Messages: [ {Content: "some content", Id: "203", IsNew: false, Subject: "some Subject"}, .... ]} I would like for 'IsNew' to be observable at the very least. To do this I was using the ko.mapping plugin //Within success of ajax call var vm = ko.mapping.fromJS(data) But I also have a need for a 'SelecetedMessage' observable and a SetSelected function on my vm. But im not sure the best way for these to be a part of my vm. Could someone explain