Solved

knockout js

Posted on 2015-01-25
1
73 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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

New Relic: Our company recently started researching several products to figure out what were the best ways for us to increase our web page speed and to quickly identify performance problems that we may be having. One of the products we evaluated wa…
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…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

762 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now