Solved

knockout js

Posted on 2015-01-25
1
78 Views
Last Modified: 2015-01-26
i have a custom binding defined as below, if i have a value it is working fine but if the value is empty i am getting an exception object is not a function at this line valueAccessor()(thisValue);
if i put a condition to check i it has a value, then the binding is not applied to that field.
ko.bindingHandlers.getter = {
        init: function (element, valueAccessor, allBindingsAccessor, context) {
              
            var $el = $(element),
                thisValue = $el.val() || $el.text();
           valueAccessor()(thisValue);
        }
    }
0
Comment
Question by:gvkr
1 Comment
 
LVL 22

Accepted Solution

by:
ambience earned 500 total points
ID: 40570251
Well, this makes sense because when you invoke

valueAccessor()(thisValue);

Open in new window


you first get the property value using

valueAccessor()

Open in new window


and then treat it as a function, which becomes

'undefined'(thisValue)

Open in new window


when the returned value is undefined. You should check the return value of valueAccessor() first.
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question