knockout

knockout “if binding” not working

匿名 (未验证) 提交于 2019-12-03 08:44:33
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: When debugging with Chrome, I can see CoverPrices has 9 elements. The foreach loop actually works well and the table looks correct with the first span being bound to Item1 correctly. However, the if binding does not work and both images are displayed. Yet, all the elements in Item2 have the true value, so only the first image should show up. <!-- ko foreach: CoverPrices --> <tr> <td> <span data-bind="text: Item1"></span> </td> <!-- ko foreach: Item2 --> <td> <img src="~/Images/yes.png" alt="oui" data-bind="if: $data" /> <img src="~/Images/no

Knockoutjs. How to compute data changed inside observable array

匿名 (未验证) 提交于 2019-12-03 08:36:05
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: Please, look at my text. I try to use observableArray of knockoutjs and foreach to compute data of array. Example 1 works fine: total sum computed if you change data in the fields. But Example 2 is not working. <html> <head> <title></title> <script type = 'text/javascript' src = '/js/jquery-1.8.2.min.js' ></script> <script type = 'text/javascript' src = '/js/knockout-2.1.0.debug.js' ></script> </head> <body> <p> Example 1 </p> <div> <p> <input data-bind = "value: fnum1" /> <input data-bind = "value: fnum2" /> <span data-bind =

knockoutjs select change event gets fired when binding

匿名 (未验证) 提交于 2019-12-03 03:10:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have this knockout code: http://jsfiddle.net/nickbuus/Rwabt/ The problem is that whenever the dropdown select box gets filled the change event gets called: How do I fix this ? 回答1: There was a lot of broken and unused code in there http://jsfiddle.net/Rwabt/5/ This one is corrected. What actually did make it call change is for two reasons, you used string in the food model and numbers in category model ("1" != 1) , Id 2 was not present in the categories (Only 1) the beer category was set for both food items (CatId 2). Since KO could not

knockout bind a key value object to dropdown

匿名 (未验证) 提交于 2019-12-03 02:56:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have the following models: var allCategories = [{ id : 1 , name : 'Red' }, { id : 5 , name : 'Blue' }]; function model () { self = this ; self . name = ko . observable ( "" ); self . categoryId = ko . observable (- 1 ); self . categoryName = ko . computed ( function () { if ( self . categoryId () == - 1 ) return "" ; return getCategoryNameById ( self . categoryId ()). name ; }); } function getCategoryNameById ( id ) { return _ . find ( allCategories , function ( cat ) { return cat . id == id ; }); } I want to offer a dropdown to

Knockout unable to process binding

匿名 (未验证) 提交于 2019-12-03 02:34:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How do I bind a text when it is undefined? For example name is not available: <table id="recordTbl" data-bind="visible: records().length > 0" class="table"> <thead> <tr> <th class="col-md-4">ID</th> <th class="col-md-4">Name</th> </tr> </thead> <tbody data-bind="foreach: records"> <tr> <td data-bind="text: id"></td> <td data-bind="text: name"></td> </tr> </tbody> </table> I get this error: Uncaught ReferenceError: Unable to process binding "text: function (){return name }" Message: name is not defined 回答1: You can you the $data binding

Knockout typescript extenders

匿名 (未验证) 提交于 2019-12-03 02:31:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Could anyone please post an example of extending an observable in knockout in typescript? Knockout extender: http://knockoutjs.com/documentation/extenders.html I am using this version of knockout.d.ts from march 6. 2013 https://github.com/borisyankov/DefinitelyTyped/tree/master/knockout EDIT: Thank you very much! So to extend you 'just' need to add the interface KnockoutExtenders so that typescript will 'allow' it. Example interface KnockoutExtenders { logChange(target: any, option: string): KnockoutObservableAny; } ko.extenders.logChange =

The rest of the owl: Knockout BindingHandlers with Typescript?

匿名 (未验证) 提交于 2019-12-03 02:31:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I am trying in earnest to follow the accepted answer for this . I'm using Knockout, Typescript, MVC, VS2017 and node modules for most of my packages. The problem I'm having is that the binding does not get called but don't have any build errors. provide a definition file (say myBindings.d.ts) add the following code interface KnockoutBindingHandlers { csharpTypes : KnockoutBindingHandler ; } Reference this definition file in your extensions.ts file Thus I created a customKoBindings.d.ts like this. /// <reference path="../../node

Knockout: Unable to process binding

匿名 (未验证) 提交于 2019-12-03 02:30:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I asked this question earlier but did not get an answer. I get this error message when I run my code: Uncaught ReferenceError: Unable to process binding "visible: function (){return !editable() }" Message: editable is not defined the editable function is supposed to toggle true/false and then switch to edit mode when a button is pressed. This button is called through a foreach in the html so i'm guessing it has something to do with my viewmodel. The output I get from my getJson works fine but the editable function conflicts somehow. Here is

Knockout content editable custom binding

匿名 (未验证) 提交于 2019-12-03 01:58:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Why in this example http://jsfiddle.net/JksKx/8/ div lost cursor when i write text? How to fix such behavior? 回答1: The keyup event is firing and writing to your viewmodel, which then triggers the update function of the custom binding. This is writing the innerHTML back to the element, which is causing you to lose focus. An easy fix is to check in the update function if the element.innerHTML already is the same as the value that you want to set it to. http://jsfiddle.net/rniemeyer/JksKx/9/ ko.bindingHandlers.htmlValue = { init: function

Does afterRender work with Knockout components?

匿名 (未验证) 提交于 2019-12-03 01:18:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: afterRender works with template bindings, but after converting my templates to components, there does not seem to be any way to use afterRender . I have tried looking for an example of a component that uses afterRender , but cannot find anything. 回答1: I could not get the method working as per the above post. However i found a workaround on the git issue list and it doesn't require a custom KO Binding. Add the below line in your component template html or string of code. Then create a init function in your module / viewModel: this.init =