python ruby-programming-language Smalltalk Vue.js Knockoutjs TypeScript JavaScript, OOPs JavaScript Angular 7, Interview Questions Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 4 Angular 2 AngularJs 1.x NodeJs Perl Programming R Programming RequireJs Rust Programming Backbonejs closure programming language go-programming-language kotlin-programming-language

knockoutjs custom bindings

Hi, i'm going to share the code sample for custom bindings in knockoutjs

I have an requirement to count and display to total employees. if have more then zero employee in employee-list, count and display.

In the 1st step, code sample for view model.

<script type="text/javascript">

// declare observable array
var totalEmployee = ko.observableArray([]);

    //get employee list form search employee method.
    var empList = searchEmployee();

    //push all items in totalEmployee array collection.
    if (empList !== undefined && empList.count > 0) {
        $.each(empList, function (i, v) {
            totalEmployee.push({ Id: v.empId, EmpName: v.empName });
catch (e) {
             //Toto: insert to logg, if any.
finally { }


In the 2nd step, code sample for view.

<!-- ko if: totalEmployee -->
     Total Employee(<!--ko text: totalEmployee --><!--/ko-->
<!-- /ko -->

<!-- ko ifnot: totalEmployee -->
     Total Employee(0)
<!-- /ko -->


Hi there! Welcome to my blog. My name is Anil Singh. I'm a author of this blog. For more detail about me, kindly refer to this link..
My Blogs - and
My Books - Interview Questions and Answers Books- Get Your Book in 15+ Digital Stores Worldwide..

You Might Also Like Powered by Blogger.
ASK Questions