knockout.js

Javascript knockout binding nested objects not working

扶醉桌前 提交于 2019-12-22 05:24:16
问题 I'm am relatively new to the use of the knockout javascript library. I'm having a problem getting an observable property which is an object of another object. Here is my code: function Customer(id) { var self = this; self.customer_id = ko.observable(id); self.custnum = -1; self.busname = ko.observable(""); self.address = ""; self.city = ""; self.state_id = ""; self.zipcode = ""; self.cnt_sal_id = ""; self.cnt_first_name = ""; self.cnt_last_name = ""; self.cnt_title = ""; //alert("customer: "

Properly indent KnockoutJS virtual elements

你离开我真会死。 提交于 2019-12-22 05:15:58
问题 I just started work on a large KnockoutJS code base in a Visual Studio MVC project. Everything so far seems fairly straightforward except the virtual elements. I understand the need and it is fairly nifty. However because the virtual elements are comments then indentation is all messed up which makes it a terrible pain to read. Is it possible to convert these to an actual html element or to get Visual Studio/Resharper to indent them correctly? For instance I have some code like the following

Suspend bindings in knockout.js 1.2.1

≯℡__Kan透↙ 提交于 2019-12-22 04:53:07
问题 Is there any option to suspend and resume bindings in knockout? Version : knockout.js 1.2.1 Our need for suspending bindings stems from the following. During some operations we have to load a lot of data from the server, eg multiple selects have their entire data changed, there are tables whose rows are dynamically added etc. Now in this current scenario, the form is fully bound with the view model. When we clear the combos and add each item, the view gets refreshed hence there is significant

How to add array of objects into observable array in knockout?

こ雲淡風輕ζ 提交于 2019-12-22 04:42:25
问题 I am getting a large array of objects through ajax and if the array has data then it will be passed to ImportObservableListItems in my viewmodel: success: function (data) { debugger if (data.length > 0) { ReadingList.ImportObservableListItems(data); } in the viewmodel I would like to add each object to an observable array but I need the properties of each object to be observable. however if the array contains a large number of objects then the browser crashes. is there any way I could prevent

Cannot write a value to a ko.computed unless you specify a 'write' option

房东的猫 提交于 2019-12-22 04:33:29
问题 I am trying to use computed properties in another computed properties and when i run code i am getting following error in console. Cannot write a value to a ko.computed unless you specify a 'write' option function AppViewModel() { var self = this; self.firstName = ko.observable('rahul'); self.lastName = ko.observable('sharma'); self.fullName = ko.computed(function() { return self.firstName() +' ' + self.lastName(); }); self.upperFullName = ko.computed(function() { return self.fullName

Mixed Knockout and Server side rendering

情到浓时终转凉″ 提交于 2019-12-22 03:22:59
问题 I have some pages that I need to render via the server side to make them search engine friendly. For search engines, it should function as a classic website. For users, I want to make the interface more interactive. My thought is to render the page server side, then use knockout and jquery to fetch the data again via ajax and bind it to the page. I'm concerned about having flashes of no content, or duplicated content. Is there a best practice/pattern for cases like this? The process would

KnockoutJS property doesn't update when changing value with Jquery

筅森魡賤 提交于 2019-12-22 02:01:06
问题 I have a serie of checkboxes and I want to gather the selected one. The checkboxes are in div's and when the div is clicked the checkbox should get checked as well: var oCheckBox = $($(this).find('.chkSocialMediaItem').get(0)); oCheckBox.attr('checked', !$(oCheckBox).attr('checked')); This works just fine but KnockoutJS doesn't pick up the change and so doesn't update my counter on the selected items. I read somewhere you need to trigger the change event. But when I listen to the change event

KnockoutJS property doesn't update when changing value with Jquery

牧云@^-^@ 提交于 2019-12-22 02:01:04
问题 I have a serie of checkboxes and I want to gather the selected one. The checkboxes are in div's and when the div is clicked the checkbox should get checked as well: var oCheckBox = $($(this).find('.chkSocialMediaItem').get(0)); oCheckBox.attr('checked', !$(oCheckBox).attr('checked')); This works just fine but KnockoutJS doesn't pick up the change and so doesn't update my counter on the selected items. I read somewhere you need to trigger the change event. But when I listen to the change event

KnockoutJS: dynamically populate dropdownlist

怎甘沉沦 提交于 2019-12-22 01:32:07
问题 I am very newbie to KnockoutJS,I have done the simple things with dropdownlist, populating and using static data but now need to perform two things dropdownlist dynamically 1.Want to populate dropdownlist dynamically (say any list), this list we can get from my controller. var InsertVal = function(name, id) { this.pname = name; this.pid = id; }; var Valuess = function() { $.ajax({ dataType: "json", url: "getParentCategory.do", success: function (data) { for(i=0;i<data.length;i++){ totalval

Ajax Post and Redirect with Model Value MVC4

a 夏天 提交于 2019-12-22 01:31:58
问题 I am submitting a page through agax post with json data and then redirecting to other view. It's working fine. $.ajax({ url: '/bus/result', type: "POST", dataType: "json", contentType: "application/json; charset=utf-8", data: ko.toJSON(bookingInfo), success: function (data, textStatus, xhr) { window.location.href = data.redirectToUrl; } }); MVC Controller [AcceptVerbs(HttpVerbs.Post)] public ActionResult Result(BusBookingInfo bookingInfo) { if (Request.IsAjaxRequest()) { return Json(new {