MVVMing with KnockoutJS
So, How we do it?
1. Obtain jQuery, you can do it by download it or linking to it directly. Note: You cannot use the version supplied by Visual studio 2010 because it’s minimum version is 1.4.2 (VS supplies 1.4.1)
3. Link your HTML file to both jQuery and KnockoutJs files
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head>
<title></title> </head> <body>
<!-- Your Page layout HTML (view) here -->
</script> </body> </html>
Note: The view-model code has to be after your HTML content.
on our HTML content let’s make a span, and bind it’s text content to a property in the view-model:
Now, when browsing our page, we’ll see the clock at the span.
Of course, there’s still need for templates, handle events such as button click or text changes but this is for later posts.