knockout.js

How to handle pagination with Knockout

泄露秘密 提交于 2019-12-17 17:32:28
问题 I have a div that is setup to bind to a observeableArray ,but I only want to show at most 50 items from that observeableArray at any given time. I want to handle this with pagination with a previous and next button along with indices on the page to allow users to cycle through pages of items from the collection. I know I could probably do this with a computedObservable and a custom data binding but I'm not sure how to do it (I'm still a Knockout neophyte). Can anyone point me in the right

How to debug template binding errors for KnockoutJS?

和自甴很熟 提交于 2019-12-17 17:18:19
问题 I keep having trouble with debugging problems in KnockoutJS templates. Say I want to bind to a property called " items " but in the template I make a typo and bind to the (non existing) property " item ". Using the Chrome debugger only tells me: "item" is not defined. Are there tools, techniques or coding styles that help me get more information about the binding problem? 回答1: One thing that I do quite often when there is an issue with what data is available at a certain scope is to replace

Knockout attr binding with attributes like 'readonly' and 'disabled'

谁说胖子不能爱 提交于 2019-12-17 16:43:23
问题 What's the suggested "best practice" way to use Knockout's "attr" data binding with standalone attributes like "readonly" and "disabled" ? These attributes are special in that they are generally enabled by setting the attribute value to the attribute name (although many browsers work fine if you simply include the attribute names without any values in the HTML): <input type="text" readonly="readonly" disabled="disabled" value="foo" /> However, if you don't want these attributes to be applied,

Sort array by date gives unexpected results

纵然是瞬间 提交于 2019-12-17 16:15:55
问题 This will sound as an easy problem but I spent my Sunday trying to figure out what's wrong with my implementation described below so I am posting it to SO as a last resort. I have a javascript application that receives data structures from a server. The server side sends the data unsorted for performance reasons. Here is a snippet of the the javascript code receiving data: var seriesRawDataArray = ko.observableArray(); ... analyticscontext.series(seriesRawDataArray).done(function () {

Get dynamically inserted HTML to work with knockoutjs

旧街凉风 提交于 2019-12-17 15:38:19
问题 I'm using JQuery DataTables for all my tables because of all the nice built-in features, but it seems the only way to customize the table layout is to set the "sDom" option attribute for the DataTable and use something like $("div.SOMECLASS").html(HTML_HERE) to insert the customized html into the table. (FYI, i'm just trying to customize the header). The problem is I want the inserted html to use knockoutjs binding. Knockout doesn't seem to initialize the binding this way. Is there a way to

Refresh observableArray when items are not observables

北战南征 提交于 2019-12-17 11:21:45
问题 Basically I have an observableArray and the values for each item are not an observable. This means when I change an item value the UI within a foreach loop of the observableArray does not update accordingly. It means a massive change if I have to set them to observable, so is there a way I can refresh either the UI or observableArray foreach manually? 回答1: Yes, you can call valueHasMutated function for your array: yourArray.valueHasMutated(); EDIT: If first didn't help you can do 'dirty'

Using knockout js with jquery ui sliders

百般思念 提交于 2019-12-17 09:49:18
问题 I'm trying to figure out if knockout js would work nicely for the following problem: I have multiple sliders that I want to link to textboxes. When the textbox is changed the corresponding slider must update to the new value and vice versa. On changing the slider value or textbox a function needs to be called that uses the input from all textboxes to calculate a result. I have my quick and dirty jQuery solution here. Would it be easy to achieve the same result in a more elegant way using

combine dynamic and static classes through css binding, knockout.js

杀马特。学长 韩版系。学妹 提交于 2019-12-17 09:38:08
问题 In knockout.js we can use css binding for static classes <div data-bind="css: {'translucent ': number() < 10}">static dynamic css classes</div> and dynamic <div data-bind="css: color">static dynamic css classes</div> I've tried http://jsfiddle.net/tT9PK/1/ to combine it in something like css: {color, translucent: number() < 10} to get dynamic class color and static translucent at the same time, but I get an error. Is there a way to do that? 回答1: You can add dynamic class by css property and

Knockout + Bootstrap 3 Radio Buttons

那年仲夏 提交于 2019-12-17 07:23:27
问题 Related to: Bootstrap Radio Button Group HTML: <div class="btn-group" data-toggle="buttons"> <label class="btn btn-primary"> <input type="radio" name="options" id="option1" value="1" data-bind="checked: optionsValue"> Option 1 </label> <label class="btn btn-primary"> <input type="radio" name="options" id="option2" value="2" data-bind="checked: optionsValue"> Option 2 </label> <label class="btn btn-primary"> <input type="radio" name="options" id="option3" value="3" data-bind="checked:

Getting “The JSON request was too large to be deserialized”

我与影子孤独终老i 提交于 2019-12-17 03:23:10
问题 I'm getting this Error: The JSON request was too large to be deserialized. Here's a scenario where this occurs. I have a class of country which hold a list of shipping ports of that country public class Country { public int Id { get; set; } public string Name { get; set; } public List<Port> Ports { get; set; } } I use KnockoutJS on the client side to make a cascading drop downs. So we have an array of two drop downs, where the first one is country, and the second one is ports of that country.