Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you console log inside a knockout template

Tags:

knockout.js

I thought this was correct:

            <div data-bind="foreach: amount_options, visible: $parent.displayAskAmoutRadioButtons()">
                <!-- ko console.log(amount_option) --><!-- /ko -->
                <label class="donor-js-amount-choice">
                    <!-- <input type="radio" class="donor-js-webware" name="gift_amt" data-bind="attr: {value: key}, checked: $parent.amountSelected"><span class="donor-js-currency-symbol" data-bind="html: $root.session.currencySymbol"></span>&nbsp;<span class="donor-js-input-currency" data-bind="text: desc"></span>&nbsp;<span class="donor-js-input-currency"></span><br> -->
                </label>
            </div>

apparently not as nothing gets out put to the console. The commented out line of tag is throwing an error about the value: key and I need to know whats inside of one of these amount_options.

Ideas?

like image 685
TheWebs Avatar asked Jan 31 '16 00:01

TheWebs


People also ask

What is applyBindings in knockout?

applyBindings do, The first parameter says what view model object you want to use with the declarative bindings it activates. Optionally, you can pass a second parameter to define which part of the document you want to search for data-bind attributes. For example, ko.

What is $data in knockout?

The $data variable is a built-in variable used to refer to the current object being bound. In the example this is the one of the elements in the viewModel.

What is knockout programming?

Knockout is a JavaScript library that helps you to create rich, responsive display and editor user interfaces with a clean underlying data model.


1 Answers

Try this. Knockout should evaluate value for binding and flush to console.

<div data-bind="text: console.log(amount_option)"></div>
like image 124
DominicEU Avatar answered Sep 28 '22 11:09

DominicEU