knockout.js

KnockoutJS dealing with bootstrap datepickers and date formats

萝らか妹 提交于 2020-01-12 11:44:11
问题 This is the datepicker binding i'm using ( im sorry but i forgot where i took it so i can't give the author proper credit. I will edit if i remember. ) ko.bindingHandlers.datepicker = { init: function(element, valueAccessor, allBindingsAccessor) { //initialize datepicker with some optional options var options = allBindingsAccessor().datepickerOptions || {}; $(element).datepicker(options); //when a user changes the date, update the view model ko.utils.registerEventHandler(element, "changeDate"

knockoutjs click binding within foreach binding

旧巷老猫 提交于 2020-01-12 07:40:48
问题 EDIT: Problem was not related to the binding but to a simple JavaScript mistake. I have a question concerning a click binding within a foreach binding. I have a list with items showing a drop down box to select a value from the master data. Items can be added and removed from that list. The button to remove items is nested in the foreach binding. Therefore I expected that I should bind it with $parent> <button data-bind="click: $parent.removeNumber">-</button> That does not work. But the

How to show validation error messge on different location?

感情迁移 提交于 2020-01-12 02:50:07
问题 I am using knockout.js & knockout.validation plugins. I am adding the example fiddle http://jsfiddle.net/hsnCW/1/ In this example there is a custom validation for array to check duplicate entries. But my problem is with the validation message. By default the error message inserted just after the element on which validation is applied.But i want to show message on some different place. How can i do this? 回答1: You can use the validationMessagebinding to display any of your proerties error

Force a computed property function to run

瘦欲@ 提交于 2020-01-11 15:18:28
问题 Given a computed property vm.checkedValueCount = ko.computed(function(){ var observables = getCurrentValues(); //an array of ko.observable[] return _.filter(observables, function(v) { return v() }).length; }); suppose getCurrentValues() can return different sets of observables which are modified elsewhere in the code (and comes from a more complex structure than an observableArray). I need checkedValueCount to update whenever one of its dependencies change getCurrentValues() returns a

Force a computed property function to run

你离开我真会死。 提交于 2020-01-11 15:18:13
问题 Given a computed property vm.checkedValueCount = ko.computed(function(){ var observables = getCurrentValues(); //an array of ko.observable[] return _.filter(observables, function(v) { return v() }).length; }); suppose getCurrentValues() can return different sets of observables which are modified elsewhere in the code (and comes from a more complex structure than an observableArray). I need checkedValueCount to update whenever one of its dependencies change getCurrentValues() returns a

What does Model View ViewModel / Knockout solve? [closed]

久未见 提交于 2020-01-11 12:52:52
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 years ago . I was reading someone's code where I came across Knockout and MVVM. I did some reading on both topics, but I'm still confused as to what problems they really solve, most likely because I just haven't built applications large enough to come across the problems that this framework

1 viewmodel multiple routes: lifecycle

て烟熏妆下的殇ゞ 提交于 2020-01-11 10:15:13
问题 I'd like to have a couple of different routes pointing to the same view/viewmodel and I have managed to make this happen. { route: 'formulation', moduleId: 'formulation', title: 'Formulation', nav: 6 }, { route: 'fabrication', moduleId: 'test', title: 'Fabrication', nav: 7 }, { route: 'fabrication/:studyId', moduleId: 'test', title: 'Fabrication' }, { route: 'characterization', moduleId: 'test', title: 'Characterization', nav: 8 }, However, I'm running into a bit of a problem with the

How to use Knockout observables in i18next?

霸气de小男生 提交于 2020-01-11 09:21:10
问题 I'm trying to somehow dynamically use i18next translations together with Knockout.js, but I cant figure out how. Neither a custom Knockout binding or the i18next jQuery plugin seems to work with observable values. A demo of what I'm trying to achieve can be found here: http://jsfiddle.net/rdfx2/1/ A workaround is something like this, but I'd rather avoid that, if possible: <div data-bind="text: translate('key', observable)"></div> self.translate = function (key, value) { return i18next.t(key,

Sortable and droppable knockout list

有些话、适合烂在心里 提交于 2020-01-11 06:50:13
问题 I have a list that needs to be draggable. For simplicity lets have the items only be "boy" and "girl". I have another list "friends" that you can drag "boy" and "girl" into then set properties such as name, age, height, etc. This list also needs to be sortable (drag and drop). Basically I want to add items to the "friends" list by dragging in either a "boy" or "girl" but I'm not sure how to get the two lists to interact using knockout. 回答1: Ryan Niemeyer has written great article about

Reapply bindings in knockout

三世轮回 提交于 2020-01-11 04:52:10
问题 I basically want to reapply bindings on the same page for the different objects, but there is strange behavior. After I reapply the binding, the list of items is lost. Please see here: http://jsfiddle.net/baio/9UcUs/5/ What to do? 回答1: The short answer is that it's not supported. The long answer is that there are some ways around it. One way is to call cleanNode before applyBindings , but this doesn't clear event handlers. Another way is to wrap your view model in an observable and then