knockout.js

How to stop Knockout 3.2 library loading twice

别说谁变了你拦得住时间么 提交于 2019-12-23 02:28:11
问题 I have the issue that binding expressions such as <div data-bind="text: $data.Property"></div> -where Property is an observable- causes the actual text of knockout's observable function to display instead of the value Property is supposed to represent. This was addressed here In IE8, KnockoutJS 3.2 displaying actual observable function rather than the observable's value. The cause of that issue was that duplicate knockout library files were being loaded. The "UPDATE:" section and answer of

KnockoutJS dynamic form validation

倾然丶 夕夏残阳落幕 提交于 2019-12-23 02:20:47
问题 I have a form that have a three field group that on a click of a "Add New" buttom other three field group will be added. That part is working great. I want to add a validation so all three fields are required in order to add a new group. For reference here is the code working: http://jsfiddle.net/5g8Xc/ var ContactsModel = function(contacts) { var self = this; self.contacts = ko.observableArray(ko.utils.arrayMap(contacts, function(contact) { return { firstName: contact.firstName, fathersLast:

Bind knockout.js to a boolean JQuery Mobile flip switch toggle

我的未来我决定 提交于 2019-12-23 02:17:33
问题 i have a boolean value bound to a JQM flip switch toggle, but i'm not able to see it reacting to changes to the underlying observable. This is my true/false observable: ko.booleanObservable = function (initialValue) { var _actual = ko.observable(initialValue); var result = ko.computed({ read: function () { var readValue = _actual().toString(); return readValue; }, write: function (newValue) { var parsedValue = (newValue === "true"); _actual(parsedValue); } }); return result; }; Which is the

Breeze.js & Knockout.js: translating breeze validation to knockout validation causes an 'Out of stack space' or 'Too much recursion'

情到浓时终转凉″ 提交于 2019-12-23 02:14:20
问题 I have a client side model generated by Breeze/OData and I used the code in this post to connect it to Knockout validation. It works great for validating individual fields through the isValid() method. However, whenever I try to use ko.validation.group against a Breeze Entity (assume that the knockout validation is configured with {deep: true} ), either calling showAllMessages , length or any other method that performs a tree traversal over the object graph, results in an infinite recursion

Uncaught TypeError: Cannot read property 'length' of undefined

爷,独闯天下 提交于 2019-12-23 01:54:38
问题 I'm working to built a contact list that is grouped by the first letter of the contact's last name. After a succesfull ajax request, the contact is pushed to addContact: Ajax success: ko.utils.arrayForEach(dataJS.contactList, function(c) { contactsModel.addContact(c); }); contactsModel.addContact: //add a contact in the right spot under the right letter contactsModel.addContact = function(newContact) { //grab first character var firstLetter = (newContact.lname || "").charAt(0).toUpperCase();

knockout set css conditionally

我怕爱的太早我们不能终老 提交于 2019-12-23 01:51:29
问题 Sorry for maybe uncorrect question, but I feel really confused. I need to set the css class of an item in a foreach loop based on the value of an item's property. self.CssBind = ko.computed(function (task) { var CssBind = ''; if (getComplexity(task) === 'Easy') { CssBind = "green"; } else if (getComplexity(task) === 'Intermediate') { CssBind = 'yellow';} else if (getComplexity(task) === 'Difficult') { CssBind = 'red'; } return CssBind; }); I tried to get complexity in such way but have

Clicking on an input[checkbox]'s label will fire twice the parent's click event (knockout)

别说谁变了你拦得住时间么 提交于 2019-12-23 01:35:11
问题 Consider this fiddle. I have an <input type='checkbox'> linked to its corresponding <label> . On their parent, I have a click binding. The problem is, clicking on the <label> will trigger the parent's click twice, whereas clicking on the <input> will trigger it only once. Considering I want to keep the current HTML structure ( <label> next to the <input> ), is there a way to make the <label> behave like the <input> element? (aka trigger the click only once) EDIT : If i remove the return true;

Using a variable to store a knockout template

谁都会走 提交于 2019-12-22 23:24:16
问题 New to knockout and loving it so far cut a 700 line jQuery mess into 150 lines. The one part I am not really liking is the templating. I want to be able to create a file similar to this module.ViewModel.views = { 'view1' : '<div data-bind="foreach: data">TEMPLATE</div>' }; // in my view model set something like ViewModel.view1Template = module.ViewModel.views.view1; // then in my html have <div data-bind="template: view1Template()"></div> I would like to be able to do this possibly with

Using a variable to store a knockout template

只谈情不闲聊 提交于 2019-12-22 23:23:53
问题 New to knockout and loving it so far cut a 700 line jQuery mess into 150 lines. The one part I am not really liking is the templating. I want to be able to create a file similar to this module.ViewModel.views = { 'view1' : '<div data-bind="foreach: data">TEMPLATE</div>' }; // in my view model set something like ViewModel.view1Template = module.ViewModel.views.view1; // then in my html have <div data-bind="template: view1Template()"></div> I would like to be able to do this possibly with

Module granularity strategies

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-22 20:45:15
问题 I'm building a KnockoutJS web app using RequireJS to modularize it. I'm trying to decide between a couple of strategies to break things into modules. Flat approach : One approach features a flatter directory structure and larger modules: /webapp |-/scripts |-/templates | |-car_edit.html | |-car-view.html | |-person_edit.html | |-person_view.html |-main.js |-person.js |-car.js As an example, the person module (in person.js) is implemented something like this: define(['jquery', 'knockout', ...]