knockout.js

Binding a custom handler twice in knockoutjs

☆樱花仙子☆ 提交于 2020-01-04 05:24:50
问题 I've written a custom binding handler to show a bootstrap popover in knockout: ko.bindingHandlers.popover = { init: function (element, valueAccessor, allBindings, viewModel, bindingContext) { $(element).popover({ html: true, content: function () { return $('#' + ko.unwrap(valueAccessor().template)).html(); }, placement: "right", trigger: "manual", container: 'body' }); }, update: function (element, valueAccessor, allBindings, viewModel, bindingContext) { if (valueAccessor().visible()) { $

Kendo grid, ko binding, and access to row index

拈花ヽ惹草 提交于 2020-01-04 04:15:12
问题 I have a ko viewmodel, which I bind to a KendoGrid, using knockout-kendo.js I use rowTemplate, because I need some custom functionality in some columns (icon, links, etc) I need to do some custom functionality based on rownumber. When binding ko viewmodel directly, I can use foreach binding and in the row template I have the $index which gives me the current row number. How can I get the same thing when the viewmodel is bound to a Kendo Grid? Thank you 回答1: Currently there is no built in

Handling load timeouts of a view in a Durandal app

五迷三道 提交于 2020-01-04 03:30:12
问题 I've got a Durandal app that will periodically timeout when attempting to load a view. Here's an example timeout error: Error: Load timeout for modules: text!views/primaryapplicants.html http://requirejs.org/docs/errors.html#timeout If you lookup the provided URL, it suggests a few possible issues: Script error in listed module Path configuration incorrect Multiple module IDs map to the same file None of these are my issue. It is a real, genuine timeout. For some reason it wasn't able to load

Knockoutjs - Sorting a large observablearray

北战南征 提交于 2020-01-04 02:09:21
问题 I have a knockout model defined on a page with an observable array. I would like to have buttons to sort the array by different properties, I have a 'working' solution but it is extremely slow for large arrays. jsFiddle - http://jsfiddle.net/7JNrc/ What is the most efficient way to sort a knockout observable array of objects by specific properties? 回答1: Your solution is slow not due to the sorting. It is slow because you bind a lot of items to one page. It takes much time to render 200 items.

disabling individual items in knockout-sortable

蹲街弑〆低调 提交于 2020-01-03 19:41:47
问题 In knockout-sortable, I know that you can disable a sortable list using isEnabled in the sortable binding. I also know you can disable moving items using cancelDrop in a beforeMove function. The problem is, isEnabled disables the whole list, and cancelDrop can only be called after the item is already dragged and dropped onto another sortable . Is there a way to disable sortable 's click/drag behavior on certain contained items? 回答1: You can use the jQuery UI sortable options items or cancel

How to get a ko.computed to work on observables inside an object

限于喜欢 提交于 2020-01-03 18:01:48
问题 I have a fairly simple view model to hold an array of data and take a string which I want to use to filter the data. I have some very simple mark-up to render it like this: <section class="task-list"> <ul data-bind="foreach:filteredRecords"> <li> <label>Task name:</label> <span data-bind="text:TaskName"></span> </li> </ul> </section> and I've set up the model as follows; var viewModel = { searchText : ko.observable(''), taskData : ko.observableArray([]), searchData : function () { // use ko

Splicing new array of items onto existing Knockout observable array causes binding errors

房东的猫 提交于 2020-01-03 17:11:11
问题 I have a knockout observable array being populated with some initial values when the web page loads, and I want to add to the observable array via splice method as the user interacts with the page. The new items I'm trying to add to the array have the exact same properties as the original items in the array, but when I try to splice the new items onto the existing array, I get a Knockout binding error, ex: " Error: Unable to parse bindings. Message: ReferenceError: ContactName is not defined;

Splicing new array of items onto existing Knockout observable array causes binding errors

痞子三分冷 提交于 2020-01-03 17:10:19
问题 I have a knockout observable array being populated with some initial values when the web page loads, and I want to add to the observable array via splice method as the user interacts with the page. The new items I'm trying to add to the array have the exact same properties as the original items in the array, but when I try to splice the new items onto the existing array, I get a Knockout binding error, ex: " Error: Unable to parse bindings. Message: ReferenceError: ContactName is not defined;

Knockout region highlighting - visual studio 2013

醉酒当歌 提交于 2020-01-03 17:08:43
问题 Knockout highlighting is not working for me in VS2013. Given that I have the "knockout highlight color" setting: ...my assumption is that it should be working. However, no dice: Any ideas? 回答1: I had the exact same issue. I am a total newbie to Visual Studio, and given that the Web Essentials listed knockoutJS intellisense out of the box I did not think one needed to do anything to 'turn it on'. Also, it seems support for Mustache templating and Angulars ng-bind syntax works out of the box so

knockoutjs get the (real bound) element through click event

你说的曾经没有我的故事 提交于 2020-01-03 13:34:11
问题 See this question. Except that the answer returns the child element when a child element is clicked, i.e. in the case that you bind a div. <div id="parent" data-bind="click: log">Parent Div<div id="child">Child</div></div> <script> var ViewModel = function() { this.log = function(data, event) { console.log("you clicked " + event.target.id); } }; ko.applyBindings(new ViewModel()); </script> See this fiddle I want to get the original element the click event was bound to. Any suggestions? 回答1: