knockout-2.0

Knockout JS + Bootstrap + Icons + html binding

核能气质少年 提交于 2019-12-05 11:02:39
ok, this one is driving me nuts... I just can't seem to figure out the correct way to make html bindings in knockout, play nicely with twitter bootstrap elements. I have, the following HTML: <li><a href="#"><i class="icon-user"></i> Enable/Disable User</a></li> This line is actually part of some other li's that are in a ul, but I'm showing ONLY the bit I need for simplicity. As you can see, I'm also using twitter bootstrap here, as is evidenced by the icon class. Ok, so that's all good, when I render my menu that a tag shows up correctly, all nicely rendered in bootstrap style, and everything

knockoutjs how to get the selected option arrayObject

跟風遠走 提交于 2019-12-05 07:06:38
I want to get the selected option object <select data-bind="options: availableCountries, value: selectedCountry, event: { select: onSelect}"></select> <script type="text/javascript"> // 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", 29000000) ]), selectedCountry : ko.observable(), // Nothing selected by default onSelect: function(){ console.log

Knockout bindingHandler for comma separated numbers

主宰稳场 提交于 2019-12-04 21:47:27
问题 I'm building a very number-heavy app in KnockoutJS and I want to have the ability to format large numbers so that they're comma-seperated and nice on the eye (xxx,xxx). As you'll see from the fiddle below, I do have this working by wrapping the binded value inside of a formatting function with a simple RegEx but the problem with this is that this overwrites the value inside the input and inserts ',' into the underlying value. The large numbers are used further down the app and so to prevent

Knockout-2.2.0, subscribe get value before change AND new value

不羁岁月 提交于 2019-12-04 17:03:48
问题 jsfiddle link: http://jsfiddle.net/T8ee7/ When I call Knockout's subscribe method is there a way I can get both the previous and new value? Right now, I can only call get these values separately. I want to trigger some code if the old and new value are different. I suppose I could do the following, but it can get messy... (http://jsfiddle.net/MV3fN/) var sv = sv || {}; sv.PagedRequest = function (pageNumber, pageSize) { this.pageNumber = ko.observable(pageNumber || 1); this.numberOfPages = ko

KnockOut Mapping Hierarchical JS object

心已入冬 提交于 2019-12-04 14:55:11
I am trying to create view Models using KnockOut mapping plugin , This is the object , Basically below is a sentence with words in it. var data = { name: 'Example Title', sentences: [ {id: 1, words: [{text: 'word1'}, {text: 'word2'}]}, {id: 2, words: [{text: 'word3'}, {text: 'word4'}]} ]}; I would like to have three view Models , Article should contain sentences , an Sentence should contain words var ArticleViewModel = function(data) { var self = this; self.id = ko.observable(data.id); self.sentences = ko.observableArray([]); } var SentenceViewModel = function(data) { var self = this; self.id

Force native Knockout Templating

半世苍凉 提交于 2019-12-04 12:40:04
I have a page that requires jQuery.tmpl, but I want to use native knockout templating for a data-bind="foreach: Comments" attribute. Because I have included jQuery.tmpl, knockout's native templating is disabled; is there a way that I can force the native functionality? Thanks You cannot use foreach or other control-flow bindings within a jQuery.tmpl template. However, if you want to call a named template and force it to use the native template engine, then you would do something like: <div data-bind="template: { name: 'itemsTmpl', templateEngine: new ko.nativeTemplateEngine() }"> </div> ​

alternate row style with $index binding

倾然丶 夕夏残阳落幕 提交于 2019-12-04 09:53:34
问题 I am having trouble getting an alternate-row css class applied to a knockout template with a foreach binding context. I am using knockout 2.1 with the available $index context variable. This is whats confusing: My Template <li class="row" data-bind="css: { alt: $index%2 }"></li> results in no alt classes being applied, however: <li class="row" data-bind="text: $index"></li> works properly and displays the row number. 回答1: I struggled with this for a couple minutes and found that this question

knockoutjs select change event gets fired when binding

和自甴很熟 提交于 2019-12-04 08:29:27
I have this knockout code: http://jsfiddle.net/nickbuus/Rwabt/ The problem is that whenever the dropdown select box gets filled the change event gets called: <select data-bind="options: $root.Categories, optionsText: 'categoryName', optionsValue: 'categoryId', value: CatId, optionsCaption: 'Vælg...', event: { change: $root.selectionChanged }"></select> How do I fix this ? There was a lot of broken and unused code in there http://jsfiddle.net/Rwabt/5/ This one is corrected. What actually did make it call change is for two reasons, you used string in the food model and numbers in category model

Jquery knockout: Render template in-memory

╄→гoц情女王★ 提交于 2019-12-04 05:41:13
I have a knockout template: <script id="draggableHelper" type="text/x-jquery-tmpl"> <div class="draggableHelper"> <span data-bind="text: Name"></span> </div> </script> Is possible to generate the result of the template, and save it into memory, by sending the object to populate the template? Something like: var result = ko.renderTemplate($("#draggableHelper").html(), { Name: "Test" }); Yes it's possible to apply bindings to nodes unattached to the DOM. Just use very useful function ko.applyBindingsToNode to achieve the desired result. ko.renderTemplateX = function(name, data){ // create

knockout - execute code after the last item has been rendered

我的未来我决定 提交于 2019-12-04 05:31:36
i'm using jquery quicksearch to search a table that is being populated by knockout foreach loop. the quicksearch element needs to be initiate after the foreach finishes . I've tried several approaches, but was unsuccessful so far. I've tries using 'afterRender', but was unable to determine if the current item is the last item on the collection, i've also tried using a bindingHandlers, but then i got a collection of length 0 instead of length 2005. so: what's the best approach to finding the last element in a foreach loop ? what's the best way to implement it in this specific scenario? here's