HTML:
<ol data-bind="foreach:newFriend">
<li>
<span data-bind="text:fullName"></span>
</li>
</ol>
JavaScript:
const obj = {
newFriend: ko.observableArray([
new friend("jesse ", "pinkman"),
new friend("walter ", "white"),
]),
};
function friend(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
this.fullName = firstName + " " + lastName;
}
HTML:
<input type="checkbox" data-bind="checked:knowJS" />
<input type="text" data-bind="value:favLib, visible:knowJS"/>
HTML:
<button data-bind="click:remove" class="remove-btn">X</button>
<input type="text" data-bind="value:newFriendLastName"/>
<input type="submit" data-bind="click:addFriend" />
JavaScript:
function friend(firstName, lastName) {
this.remove = function () {
obj.newFriend.remove(this);
};
}
obj.addFriend = function () {
obj.newFriend.push(
new friend(obj.newFriendName(), obj.newFriendLastName())
);
};
Number of Friends : /5
HTML:
<p>
Number Of Friends :
<span data-bind="text:newFriend().length"></span>/5
</p>
<input
type="submit"
data-bind="click:addFriend, enable:newFriend().length < 5"
/>