knockout.js

PagerJS how to build a navbar?

好久不见. 提交于 2020-01-21 12:12:36
问题 My goal is to write some reusable code to render basic navbars, since it would be a very repetitive task. The following features are my first goal: Each page should be rendered in a foreach binding Each page should grab the active state reading current route Each page should be loaded either async or inline Here's my first attempt. I want markup to be something like this <ul data-bind='foreach: pages'> <li> <!-- [1] Here a toggler is needed for active/no-active status, i.e. a class binding. -

PagerJS how to build a navbar?

不想你离开。 提交于 2020-01-21 12:12:05
问题 My goal is to write some reusable code to render basic navbars, since it would be a very repetitive task. The following features are my first goal: Each page should be rendered in a foreach binding Each page should grab the active state reading current route Each page should be loaded either async or inline Here's my first attempt. I want markup to be something like this <ul data-bind='foreach: pages'> <li> <!-- [1] Here a toggler is needed for active/no-active status, i.e. a class binding. -

Getting $index of grand parent in a nested loop

£可爱£侵袭症+ 提交于 2020-01-21 10:39:15
问题 How to access the index of the grand parent in the nested loop? For example: <div class="loop" data-bind="foreach: rows"> <div class="nested-loop" data-bind="foreach: cells"> <div class ="nested-nested-loop" data-bind="foreach: candidates, css : {selected : $root.isSelected($parentContext.$parentContext.$index(), $parentContext.$index(), $index())}"> Candidate index: <span data-bind="text: $index()"></span> Cell index: <span data-bind="text: $parentContext.$index()"></span> Row index: <span

Can I applyBindings to more than one DOM element using Knockout?

痞子三分冷 提交于 2020-01-21 03:04:07
问题 I've got a structure like this: <div id='col1'> ... some ko elements ... </div> <div id='col2'></div> <div id='col3'> ... some more ko elements ... </div> ... and I need to be able to ko.applyBindings to col1 and col3 . Right now, I'm doing something like this to bind to col1 : ko.applyBindings(myViewModel, document.getElementById("col1")); That works fine to populate the first column. But I still lack the third column. I'd love to be able to do this: <div id='col1' class='bindable'> ... some

Using KnockoutJS with detached nodes

这一生的挚爱 提交于 2020-01-20 08:15:08
问题 What I'm looking to do is detach some nodes using jQuery's detach method, update my ViewModel, attach my nodes back, and have the values be updated. Is this possible? Here's a full fiddle of what I'm shooting for. Basically, I'd like to be able to go from left to right, click detach, update, and attach and have fresh values in the textboxes. UPDATE Based on RP's answer, the best bet, assuming this fits your use case, is to attach them to the dom hidden , update your viewmodel, and then show

Knockout force select update binding

≡放荡痞女 提交于 2020-01-17 11:17:12
问题 I have an address form for multiple addresses. http://jsfiddle.net/VAs5r/6/ When the form is loaded, the addresses object has a value Active:false that is bind to the enable property to all the input fields in order to block any entry. Then a button named "new address" change the Active property to true in order to enable all the inputs and let the user to enter information. Is working but the problem is that is not refreshing the fields until you change the select option and then return

How to load koLite with requirejs?

南楼画角 提交于 2020-01-17 10:57:50
问题 This is from knockout.dirtyFlag.js ;(function (ko) { ko.DirtyFlag = function (objectToTrack, isInitiallyDirty, hashFunction) { hashFunction = hashFunction || ko.toJSON; var _objectToTrack = objectToTrack, _lastCleanState = ko.observable(hashFunction(_objectToTrack)), _isInitiallyDirty = ko.observable(isInitiallyDirty), result = function () { var self = this; self.isDirty = ko.computed(function () { return _isInitiallyDirty() || hashFunction(_objectToTrack) !== _lastCleanState(); }); self

How to load koLite with requirejs?

假装没事ソ 提交于 2020-01-17 10:55:26
问题 This is from knockout.dirtyFlag.js ;(function (ko) { ko.DirtyFlag = function (objectToTrack, isInitiallyDirty, hashFunction) { hashFunction = hashFunction || ko.toJSON; var _objectToTrack = objectToTrack, _lastCleanState = ko.observable(hashFunction(_objectToTrack)), _isInitiallyDirty = ko.observable(isInitiallyDirty), result = function () { var self = this; self.isDirty = ko.computed(function () { return _isInitiallyDirty() || hashFunction(_objectToTrack) !== _lastCleanState(); }); self

Converting the form of an observable array and displaying in select list

蹲街弑〆低调 提交于 2020-01-17 06:23:42
问题 I have an observable array as below.. var myObservableArray = ko.observableArray(["Bungle","George","Zippy"]); I wish to copy the elements into another observable array but in the following format where type is always unknown.. var anotherObservableArray = ko.observableArray([ { name: "Bungle", type: "Unknown" }, { name: "George", type: "Unknown" }, { name: "Zippy", type: "Unknown" } ]); If the original myObservableArray changes, anotherObservableArray also needs to change. Any help is

Where should I use parentheses with Knockout Computed and arrays

浪子不回头ぞ 提交于 2020-01-17 03:28:04
问题 I am combining an Options binding and a Computed, and am getting the error in the Firebug console: TypeError: this.selectedCountryNeverNull is undefined This is the relevant part of the ViewModel: // Constructor for an object with two properties var Country = function (name, population) { this.countryName = name; this.countryPopulation = population; }; var viewModel = { availableCountries: ko.observableArray([ new Country("UK", 65000000), new Country("USA", 320000000), new Country("Sweden",