knockout.js

observableArray bound table does not update when inside a jQuery UI dialog

不想你离开。 提交于 2020-01-06 23:55:49
问题 I'm trying to create a page with a button which, when clicked, opens a modal dialog box that allows a user to search for products and add selected search results to an order. I've created what I thought would work (jsfiddle sample), however the search results table, which is bound to an observableArray , does not update. If I remove the data-bind attribute from the <div id="myDialog"/> then the search results table updates correctly. Also, I could only get the jsfiddle sample to repeat the

Having trouble making Knockout and jCarouselLite to work

若如初见. 提交于 2020-01-06 23:47:33
问题 I have this knockoutjs code that loads images: self.getStudents = function (country) { $.getJSON("/home/getStudents?country=" + country, function (result) { if (result.data.length > 0) { self.properties.removeAll(); ko.utils.arrayMap(result.data, function (s) { self.properties.push({ id: property.Item.Id, address: s.address, city: s.city, state: s.state, country: s.country, image: s.image }); }); //alert(self.properties().length); jQuery(".feature-slider").jCarouselLite({ btnNext: ".slider

Showing Modal (light-box) to display items using Knockout JS

北战南征 提交于 2020-01-06 19:32:13
问题 I am working on a demo and I have two lists. Phones Favorite Accessories The Phone list shows phone name and its accessories and another list shows just the favorite accessories. The Phone list has an 'Edit' button. I would like to add a Modal dialog (or lightbox) to the 'Edit' button which would display all the favourite accessories. There should be a 'Save' button inside the Lightbox, which would save the favourite accessories against the product. Please have a look at my demo in JSFiddle

Knockout mapping complex object

烈酒焚心 提交于 2020-01-06 15:16:34
问题 For example, we have complex object: var complex = {a: 1, b: 2, c: {c1: 1, c2: 2}}; We want it to make observable: var observableComplex = ko.mapping.fromJS(complex); Question: why we get c variable not observable? I was seen somewher in manuals, that this is done by design and I want to know why? a - observable, b - observable c - object: c1 - observable c2 - observable 回答1: There is no object for 'c' that can be mapped...if you want it to be observed, you need to create a custom mapping for

Knockout mapping complex object

帅比萌擦擦* 提交于 2020-01-06 15:15:16
问题 For example, we have complex object: var complex = {a: 1, b: 2, c: {c1: 1, c2: 2}}; We want it to make observable: var observableComplex = ko.mapping.fromJS(complex); Question: why we get c variable not observable? I was seen somewher in manuals, that this is done by design and I want to know why? a - observable, b - observable c - object: c1 - observable c2 - observable 回答1: There is no object for 'c' that can be mapped...if you want it to be observed, you need to create a custom mapping for

Knockout initializing empty form inputs not work after sorting sortable form elements

那年仲夏 提交于 2020-01-06 13:09:10
问题 Here is fiddle jsfiddle.net/jw7Je I have a view model bounded to a two templates and an editable form in a single page. The two templates are initially loaded with sample data, The form is displayed without sample data through this custom binding ko.bindingHandlers.emptyInit = { init: function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) { element.value = ''; } } <input type="text" data-bind="value: jw_fullname, valueUpdate: 'afterkeydown', emptyInit: emptyInit"

Knockout JS - How to return empty strings for observable fields

主宰稳场 提交于 2020-01-06 13:02:13
问题 Im building a CRUD system where users can add, delete and edit data from a simple table. I have a modal form that is used to show additional details and also adding new incidents. Currently the modal form loads correctly for editing but has issues when trying to add a new incident. After some debuging it seems that the issue comes from this line: self.currentIncident(null); This breaks my modal form because my observable is coming back null (obviously). I was hoping that it would return

Mapping a nested object as an observable from a complex JSON using the create callback

♀尐吖头ヾ 提交于 2020-01-06 11:45:10
问题 I've got a complex object in a JSON format. I'm using Knockout Mapping, customizing the create callback, and trying to make sure that every object that should be an observable - would actually be mapped as such. The following code is an example of what I've got: It enables the user to add cartItems , save them (as a JSON), empty the cart, and then load the saved items. The loading part fails: It doesn't display the loaded option (i.e., the loaded cartItemName ). I guess it's related to some

Mapping a nested object as an observable from a complex JSON using the create callback

跟風遠走 提交于 2020-01-06 11:45:06
问题 I've got a complex object in a JSON format. I'm using Knockout Mapping, customizing the create callback, and trying to make sure that every object that should be an observable - would actually be mapped as such. The following code is an example of what I've got: It enables the user to add cartItems , save them (as a JSON), empty the cart, and then load the saved items. The loading part fails: It doesn't display the loaded option (i.e., the loaded cartItemName ). I guess it's related to some

KnockoutJS Maximum Call stack size exceeded

邮差的信 提交于 2020-01-06 08:44:12
问题 I have this code: self.EditItemPopup = function (something) { var temp = ko.mapping.toJS(something); //self.ItemToEdit = ko.mapping.fromJS(temp, EditItem, self.ItemToEdit); ko.mapping.fromJS(temp, EditItem,self.ItemToEdit); self.FindMatchingCategory(something.CategoryID()); $("#editItemPopup").dialog("open"); }; self.FindMatchingCategory = function (categoryID) { ko.utils.arrayForEach(self.ViewModel().Categories(), function (categoryToFind) { if (categoryToFind.CategoryID() == categoryID) {