knockout.js

Change event doesn't trigger when Knockout updates value

孤街浪徒 提交于 2019-12-21 07:17:45
问题 I have an external javascript library which triggers on the change of a textarea, formats it, etc. However, when KnockoutJS sets the value to the textarea, the change event isn't fired. Simplified Fiddle of my problem. Is it possible to fire the change event when Knockout updates the value of my textarea? 回答1: Rather than trying to force Knockout to work with change events you can setup a subscription on the underlying observable. Like this: http://jsfiddle.net/EZC9E/1/ this.text.subscribe

Change event doesn't trigger when Knockout updates value

萝らか妹 提交于 2019-12-21 07:17:05
问题 I have an external javascript library which triggers on the change of a textarea, formats it, etc. However, when KnockoutJS sets the value to the textarea, the change event isn't fired. Simplified Fiddle of my problem. Is it possible to fire the change event when Knockout updates the value of my textarea? 回答1: Rather than trying to force Knockout to work with change events you can setup a subscription on the underlying observable. Like this: http://jsfiddle.net/EZC9E/1/ this.text.subscribe

knockout - HTML href

泪湿孤枕 提交于 2019-12-21 06:56:30
问题 I have a foreach loop that goes through an array (filesObservableArray). The array has a key/value with the key: URLPath. When I bind the array within the HTML, I would like to set the 'href=' value with the URLPath. I know this part is a fail, but conceptually, can you see what I'm trying to do? href="< span data-bind='text: URLPath'>" Or maybe I can use a 'databind="click: someCode(url)"' and within the someCode function, open the link? The url maps to either a document file (e.g., .doc) or

How to apply component bindings after ko.applyBindings() call

北城余情 提交于 2019-12-21 06:22:51
问题 Is there a way to apply component bindings after the ko.applyBindings() call? The point is, I use requireJS to load my modules/components async. So how do I know that all bindings are registered? Demo JS Fiddle ko.applyBindings(); ko.components.register('my-component', { viewModel: function() { this.name = ko.observable('My Name'); }, template: '<input type="text" data-bind="value: name"></input>' } ); // Moving it here, it works: // ko.applyBindings(); 回答1: There are a couple of pieces that

KnockoutJs - how to use datatables with existing bound table

送分小仙女□ 提交于 2019-12-21 06:00:33
问题 I have a simple HTML table which is bound using knockoutJS. However, I've added a custom binding which applies the jquery datatable plugin on the table. When I click the headers, the table disappears. Any idea how I can get it working with knockoutJS? 回答1: Its actually unnecessary to use knockoutJs to carry out the binding of the dataTable. As knockoutJs already binds the HTML table to the model, just use the following: $(function() { var dtOptions = { "bPaginate": false, "bLengthChange":

Knockout-Kendo Grid with batch editing doesn't update the viewmodel

回眸只為那壹抹淺笑 提交于 2019-12-21 05:39:32
问题 I don't know what is wrong with my implementation but I can't get my viewmodel updated if I'm using editable KendoUI Grid with Knockout-Kendo. If I change some particular table field and log the viewmodel it will not get any update. <button data-bind="click: log">Log ViewModel</button> <div id="gr" data-bind="kendoGrid: options"></div> var pStyleHeader_ViewModel = function() { this.options = { data: ko.observableArray([{ StyleNo : ko.observable("1BA0012"), Description : ko.observable(""),

Delete Item from List using Knockout.js

早过忘川 提交于 2019-12-21 05:15:26
问题 I am trying to delete an item from a list. I am using knockout.js with the mapping plugin. My code looks like this: Serialize to Json @{ var jsonData = new HtmlString(new JavaScriptSerializer().Serialize(Model));} Template <script type="text/html" id="imgsList"> {{each model.Imgs}} <div style="float:left; margin: 10px 10px 10px 0;"> <div><a href="${Filename}"><img src="${Filename}" style="width:100px;"></img></a></div> <div data-bind="click: deleteImage">Delete</div> </div> {{/each}} </script

Why is my BootstrapSwitch not working in a knockout table built using a foreach

痴心易碎 提交于 2019-12-21 05:09:24
问题 I'm trying to replace a checkbox in a table with this good looking bootstrap switch. I'm also using knockout and the binding handler as suggested by this link. However I cannot get the binding handler to work and or the switch to be clickable in the table built using a knockout for each. I've replicated the issue in a jsfiddle. I'm still learning javascript and knockout and just cannot figure out what's going wrong in the binding handler or switch. Any ideas? The Html: <div> <input type=

How to create an observable array with undo?

牧云@^-^@ 提交于 2019-12-21 05:09:18
问题 I am trying to add knockout JS to a search page on our website. Currently you open up a jQuery dialog box, which has a number of checkboxes of criteria that you can select. There are multiple dialogs with multiple types of criteria. When you open the dialog, the checkboxes do not take effect until you hit an "Update" button, if you click cancel or just close the window, the changes you made get reverted and the dialog is set to its former state. I read this and a few other posts. However this

Using bootstrap button dropdowns with knockout

前提是你 提交于 2019-12-21 05:01:14
问题 I'm attempting to use bootstrap's nicely styled button dropdowns with knockout. Unfortunately the dropdowns are built using links rather than <select> and knockout-bootstrap doesn't have any handlers that help. I've been able to get all the stylings to work (button type, icons, selected/deselected). But, I still can't get the click function to work: JS Fiddle Example <div class="btn-group"> <!-- Change button type based on status --> <button type="button" class="btn btn-small dropdown-toggle"