knockout-2.0

How to validate an array?

懵懂的女人 提交于 2019-11-30 04:02:34
问题 I am trying to use knockout validation lib to validate an array of objects. It is not straightforward to me how to form a validation group for an array of observables. The only way I managed to make it work is like this (JSFIDDLE included): var Note = function () { var self = this; self.name = ko.observable().extend({ required: true }); }; var viewModel = function() { var self = this; self.notes = ko.observableArray([new Note(), new Note()]); self.validatedObservables = function() { var arr =

Formatting Date in Knockout Template

耗尽温柔 提交于 2019-11-30 01:40:22
问题 I'm wanting to format a date in knockout's template. The date is currently being returned as 2013-07-04T00:00:00 I would like it to be displayed like 07/04/2013 Here is the binding I'm using <td data-bind="text: FirstDate"> Are their default formatting properties in Knockout's template? 回答1: There is nothing built in regarding date formatting or formatting in general in Knockout. The text binding just converts the property value to string so if you want custom formatting you need to do it

Knockout Twitter Bootstrap Popover Binding

流过昼夜 提交于 2019-11-29 14:51:50
问题 I am trying to create a custom binding for twitter boostrap popovers that references a template but I am having trouble with the binding part of the content inside of the popover once it has been created. I have seen this question asked before but I feel like they were mostly pretty messy and I am pretty close to a reusable solution that uses templates how I want to. http://jsfiddle.net/billpull/Edptd/ // Bind Twitter Popover ko.bindingHandlers.popover = { init: function(element,

Using Underscore Template with Knockout using interpolate due to asp.net

半城伤御伤魂 提交于 2019-11-29 12:20:12
Issue I need to use the underscore template instead of the default KnockoutJS template engine due to performance. However, since I'm in an asp.net environment the default tags of <% and %> will not work because of the asp.net handler. Working jsFiddle Not Working jsFiddle What I need is to apply something like the following: _.templateSettings = { interpolate : /\{\{(.+?)\}\}/g }; Making it use the {{ and }} tags Note 7: Using the Underscore.js template engine The Underscore.js template engine by default uses ERB-style delimiters ( <%= ... %> ). Here’s how the preceding example’s template

Setting the id attribute with knockoutjs including a prefix

我只是一个虾纸丫 提交于 2019-11-29 10:29:49
问题 I'm using KnockoutJS to iterate over an object, like this: Now this all works. But the problem i have is that it sets the id of the button to just a number. So it looks like this: <button id="1">Button 1</button> <button id="3">Button 2</button> <button id="8">Button 3</button> So i tried to put a prefix in front of the the 'Id' property, like so: <div data-bind="foreach:Items"> <button data-bind="text: Name, attr: {'id': 'myprefix_' + Id}"></button> </div> But that doesn't seem to be working

Update Knockout.js Observable from JSON

喜夏-厌秋 提交于 2019-11-28 21:32:18
I'm attempt to establish a grid and update it with more records via JSON. In this simple example I am able to achieve the required functionality but I can only update / push one JSON record. I would like to be able to add multiple records via JSON? How could I achieve this? I assumed I might have to create some sort of for loop and push each JSON result to the observable but I was hoping that knockout might have a better way of updating / parsing via JSON? Heres a copy of what I have achieved so far: http://jsfiddle.net/sparkhill/crSbt/ function Users(user_id, password) { this.user_id = ko

How to get Selected Text from select2 when using <input>

本小妞迷上赌 提交于 2019-11-28 17:09:21
I am using the select2 control, loading data via ajax. This requires the use of the <input type=hidden..> tag. Now, I want to retrieve the selected text. (The value property in the data-bind expression sotres the id only) I have tried $(".select2-chosen").text() , but this breaks when I have multiple select2 controls on the page. As of Select2 4.x, it always returns an array, even for non-multi select lists. var data = $('your-original-element').select2('data') alert(data[0].text); alert(data[0].id); For Select2 3.x and lower Single select: var data = $('your-original-element').select2('data')

Angular.js vs Knockout.js vs Backbone.js [closed]

本小妞迷上赌 提交于 2019-11-28 15:03:24
I am considering to use either Knockout or Angular or Backbone for my personal project. I need to build some bigger, longer-running client-side interactions to go with my server-side stuff. I want a simple and effective way to manage data-driven user interfaces. Which framework would you choose to solve my problem described above based on the feasibility as well as the performance aspect? aet It depends on the nature of your application. And, since you did not describe it in great detail, it is an impossible question to answer. I find Backbone to be the easiest, but I work in Angular all day.

Knockoutjs (version 2.1.0): bind boolean value to select box

跟風遠走 提交于 2019-11-28 09:01:53
I want to bind boolean value to select element using KO v2.1.0, but obviously it doesn't work as expected. html code: <select data-bind="value: state"> <option value="true">On</option> <option value="false">Off</option> </select> Javascript code: var model = { state: ko.observable(false) }; ko.applyBindings(model) So I expect the select box goes to "Off" position with the initial value false but it was at "On". If I put state: ko.observable("false") it will be correct but that's not I wanted. Anyone know how to bind the boolean value to select box with KO? Jsfiddle: http://jsfiddle.net

Knockout is slow when unchecking checkboxes on a large (1000) dataset

﹥>﹥吖頭↗ 提交于 2019-11-28 06:31:57
问题 I am using this code, to check all checkboxes on my view. var checked = self.includeAllInSoundscript(); var contents = self.filterContents(self.getFilters()); for (var i = 0; i < contents.length; i++) { contents[i].includeInSoundscript(checked); } return true; The checkbox <input type="checkbox" data-bind="checked: includeInSoundscript" title="sometitle" /> This is what contents is: (function (ko) { ContentViewModel = function (data) { this.orderId = data.orderId; this.contentReferenceId = ko