DO YOU NEED A CONTENT WRITER FOR YOUR BUSINESS?

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

Dependency Tracking – KnockoutJS

Share

Using a single object called dependency tracker i.e. ko.dependencyDetection you can determine when the value get updated. When you declare a computed observable, KO immediately gets its initial value and updated computed observable.

Lets see an example for Dependency Tracking:

<!DOCTYPE html>
<html>
<head>
<title>Dependency Tracking - KnockoutJS</title>
<script src="http://ajax.aspnetcdn.com/ajax/knockout/knockout-3.1.0.js" type="text/javascript"></script>
</head>
<body>
<div>
<form data-bind="submit: addCountry">
<b>Add Country:</b>
<input data-bind='value: newCountry, valueUpdate: "afterkeydown"'/>
<button type="submit" data-bind="enable: newCountry().length > 0">Add Country</button>
<p><b>Your Country List:</b></p>
<select multiple="multiple" width="50" height="auto" data-bind="options: countries"> </select>
</form>
</div>
<script>
var AddCountry = function(countries) {
this.countries = ko.observableArray(countries);
this.newCountry = ko.observable("");
this.addCountry = function() {
if (this.newCountry() != "") {
this.countries.push(this.newCountry());
this.newCountry("");
}
}.bind(this);
};

ko.applyBindings(new AddCountry(["India", "Australia", "South Africa", "Zimbabwe"]));
</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

Silent Layoffs in Indian Tech Sector: Subtle Signs Employees Shouldn’t Ignore

Introduction Layoffs have always been a part of corporate life, but the way they’re happening…

1 day ago

Moving Made Mindful: Car Shipping Tips That Align With Your Lifestyle

Relocating is often an exciting milestone, whether you’re starting a new job, heading to college,…

2 days ago

Do Keyword-Focused Domains Have Relevance for Voice Search Today?

When you select cheap domain names, it can have a significant impact on the success…

4 days ago

VPS Hosting for Resource-Intensive Applications: What You Need to Know

Shared hosting struggles to keep up the performance commitment. Therefore, low-cost VPS hosting is an…

4 days ago

How Dermatologists Treat Melasma Without Over-Bleaching the Skin

Does your melasma return every summer despite months of treatment? Melasma appears as brown or…

5 days ago

The “Natural Aging” Look: How to Embrace Graceful Aging With the Right Care

Fine lines, sagging skin, and uneven tone—these are common signs of aging that many people…

5 days ago