DO YOU NEED A CONTENT WRITER FOR YOUR BUSINESS?

Your One-Stop Solution for All Content Needs! Click here for more!
KnockoutJS

KnockoutJS – Templating

Share

Using template is very easy to incorporate into website. For a duplication you don’t need to write over and over again just call them repetitively.

Parameters:
Following properties can be sent as a parameter-value:
name, nodes, data, if, foreach, as, afterAdd, afterRender, beforeRemove.

Lets see an example of Templating:

<!DOCTYPE html>
<head>
   <title>KnockoutJS - Templating</title>
   <script src="http://ajax.aspnetcdn.com/ajax/knockout/knockout-3.3.0.js" type="text/javascript"></script>
</head>
<body>

    <h2>Products List</h2>
    <div data-bind="template: { name: 'product-template', foreach: products }"></div>

    <script type="text/html" id="product-template">
    <div>
    Product: <span data-bind="text: product"></span><br />
    Quantity: <span data-bind="text: qty"></span><br />
    Price: <span data-bind="text: price"></span><br />
    <button data-bind="click: $root.removeProduct">Remove</button><br /><br />
    </div>
    </script>

    <script type="text/javascript">
    function MyViewModel() {
        self= this;
        this.products = ko.observableArray([
        { product: 'Cakes', qty: 15, price: '220.50' },
        { product: 'Biscuits', qty: 20, price: '117.65' },
        { product: 'Breads', qty: 7, price: '55.00' }
        ])
        
        self.removeProduct = function(){
            self.products.remove(this);
        }
    }
    ko.applyBindings(new MyViewModel());
    </script>
</body>
</html>
Namaste UI (Author)

Namaste UI collaborates closely with clients to develop tailored guest posting strategies that align with their unique goals and target audiences. Their commitment to delivering high-quality, niche-specific content ensures that each guest post not only meets but exceeds the expectations of both clients and the hosting platforms. Connect with us on social media for the latest updates on guest posting trends, outreach strategies, and digital marketing tips. For any types of guest posting services, contact us on info[at]namasteui.com.

Published by
Namaste UI (Author)

Recent Posts

5 Secrets of Online Trading You Should Know

Online trading has brought ease of trading, better security protocols, and fast trade executions; however,…

1 week ago

Top Brand Promoter Agency in India | Increase Retail Sales by 40%

Very few brands suffer from a product issue. It's a conversion issue. People enter DMart,…

2 weeks ago

Retail KYC Collection & Verification Services in India | Fast & Compliant

The onboarding process of the retailer, distributor, or partner may soon become problematic if there…

2 weeks ago

All You Need to Know about Low THC Oil Registry Card Georgia

Many of the states in the United States of America allow the use of medical…

3 weeks ago

Easy Ways to Strengthen Online Security and Privacy

Did you know that every time you browse this website or any other, you leave…

4 weeks ago

Play Anytime, Anywhere with GameZone Arcade Games

Online casino has gained immense popularity with the rise of online casinos. Platforms like GameZone…

4 weeks ago