knockout.js

Preselect a value in a dropdown using knockout

*爱你&永不变心* 提交于 2019-12-24 07:00:10
问题 I have multiple 10 dropdowns to be displayed in the page. I am using knockout to build the page. Basically i have a collection of 'sites' obseravablearray. Inside 'site' array i have a collection of 'users' which is an observablearray. 'users' are displayed as dropdown. I need to preselect a value based inside the dropdowns. However it is not working. I am not able to see the selected value in the dropdown. Please let me know for any help. I would not hardcode any id value for the dropdown as

KnockoutJS : Validate model's property only if the bound control is visible

别来无恙 提交于 2019-12-24 06:58:52
问题 I have model in a page that is bound to several controls. Based on some condition some of these controls will be visible or invisible. And on the final submit I should only validate those which are visible. The following is a sample code to explain my requirement <script src="knockout-3.4.0.js" type="text/javascript"></script> <input type="checkbox" data-bind="checked:requireAge" >Age Required</input><br /> Name : <input data-bind="value:Name" /><br /> <div data-bind="visible:requireAge"> Age

Knockout checked and click both (prevent double checkbox switch)

倾然丶 夕夏残阳落幕 提交于 2019-12-24 04:21:57
问题 I have the checkbox described like this: <input id="checkbox1" type="checkbox" data-bind=" click: function () { handle_compare($element) }, checked: is_product_compared"> .handle_compare() just inverts the observable "is_product_compared", the problem is to allow a normal behavior to this checkbox, if I click on it, seems it double switches, and I never see the changes. If I bind handle_compare to button - all is ok, checkbox switches normally. Is there a way to allow both this bindings? You

Copying an item rather than moving in the knockout sortable seating chart example

回眸只為那壹抹淺笑 提交于 2019-12-24 04:08:07
问题 This is the seating chart example of knockout sortable: http://jsfiddle.net/UdXr4/ Based on the answers of this and this, I tried to change the seating chart example such that the items from available students copied rather than moved as in the jsfiddle here The changes are shown below : ...... ...... <div class="seats" data-bind="sortable: { data: students, allowDrop: $root.isTableFull, dragged: handleDraggedItem }"> ...... ...... <div class="new" data-bind="sortable: availableStudents">

unable to get intellisense for knockout.js file

断了今生、忘了曾经 提交于 2019-12-24 03:44:27
问题 i am working on asp.net website and we are using knockout.js. I am not able to get javascript intellisense for knowkcout.js file. I tried adding the below snippet but still i am not getting any intellisense. <% if(false){ %> <script src="knockout-2.0.0.js" type="text/javascript"></script> <% } %> This is how my head block looks like: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <% if(false){ %> <script src="knockout-2.0.0.js" type="text

KnockoutObservableArray with typed elements in TypeScript

橙三吉。 提交于 2019-12-24 03:39:12
问题 I'm currently looking to migrate our project to TypeScript. I've found this great set of definition files and I'm currently experimenting with the one for Knockout. I know the definition file has a type for the observableArray KnockoutObservableArray and I also am aware you can define a typed array like MyType[] . I'd like to know if I can somehow combine these two? I'd like to create a KnockoutObservableArray for which the elements should be of type MyType . Thanks in advance! 回答1: The road

knockout.js changing the hasfocus value does not update binding value

我怕爱的太早我们不能终老 提交于 2019-12-24 03:22:56
问题 I have http://jsfiddle.net/ksCSn/1/ HTML <input type="text" data-bind=" value: title, hasfocus: edit, onEnter: stopEdit" /> <p data-bind="text: title"></p> JS ko.bindingHandlers.onEnter = { init: function(element, valueAccessor, _, viewModel) { ko.utils.registerEventHandler(element, 'keydown', function(evt) { if (evt.keyCode === 13) valueAccessor().call(viewModel); }); } } function ViewModel() { this.title = ko.observable("default value"); this.edit = ko.observable(false); this.stopEdit =

ko.computed do not fire function upon instantiating

a 夏天 提交于 2019-12-24 03:22:47
问题 Hi is there a way to not fire the function when instantiating a ko.computed example is i have this ko.computed ko.computed(function(){ alert(this.Test); } , this); so basically if i instantiated this computed this will fire the function defined there is there a way not to fire it upon instantiation? and only fire it when dependency change? 回答1: You need to set the deferEvaluation option: deferEvaluation — Optional. If this option is true , then the value of the computed observable will not be

Updation of object inside observable array is done but changes are not coming on browser

无人久伴 提交于 2019-12-24 02:59:06
问题 There is issue which I am facing right now.I have observable array which contains list of objects.Whenever I updating property of any object of array.It is not reflected on browser.I have use all knockout functions like replace,remove.But the updation coming in observable array but not in browser. Here is a sample of my issue: var ViewModel=new { self=this; self.List=ko.observableArray([]); } $(function(){ ko.applyBinding(ViewModel); }) $.post('/url',{},function(data){ ViewModel.List(data); /

Knockout: Error: You cannot apply bindings multiple times to the same element when refreshing page

ぐ巨炮叔叔 提交于 2019-12-24 02:44:04
问题 I'm using Knockout to bind an MVC view. This works fine the first time but for subsequent refreshes Knockout throws the error: Error: You cannot apply bindings multiple times to the same element. This is my binding code (inside Document.Ready), note that I am using setTimeout to run every 25 seconds, this is where the error occurs: function viewModel() { Loading = ko.observable(true), CurrentUser = ko.observable(), Environments = ko.observableArray(), CurrentFormattedDate = ko.observable() }