SlideShare a Scribd company logo
1 of 13
MVVM magic in
SharePoint 2010
using KnockoutJS!
Ajay Nayak
Cap Area SharePoint SIG
08/14/2012
About Me
• SharePoint “jack of all trades”
• Booz Allen Hamilton
• 5 years working exclusively with SharePoint
  2003/2007/2010
• Things that excite me:
  • Well-constructed SharePoint solutions
  • HTML5
  • Mountain biking
  • Craft beer
• @ajaynayak
• ajaynayak {at} gmail {dot} com
Client-side Development
• Coding on the client (HTML, JavaScript, CSS) vs.
  the server (.NET, Java)
• Modern browsers combined with new standards
  (HTML5) and powerful frameworks (jQuery)
• Users have come to expect asynchronous
  operations and rich UI interaction
What about SharePoint?
• Client-side tools at our disposal
  • SP2010 client-side object model
  • SPServices library
  • REST web services to interact with
• Reasons for developing client-side applications
  • Easy to deploy
    • Simple as pushing element files into document
      libraries
  • “Cloud ready”
    • The SP2013 “Cloud App Model” encourages JS on
      the client and RESTful services in the cloud
The Dilemma…
• How do we manage the interaction between
  HTML, JavaScript, CSS, and web services?

• jQuery provides us a powerful framework, but
  how do we structure our app in a way that
  preserves functionality, but reduces “code
  bloat”?
Model-View-Viewmodel
• Architectural pattern created by Microsoft for WPF
  development
• Separates UI from the Data layer and Business Logic
• Model
  • Defines the objects
• View
  • Defines the user interface
• Viewmodel
  • Defines how the user interface (View) is integrated with the data
    (Model)
Common MVVM Scenario
• The Model is defined server-side and is sent to the client in
  the form of a JSON (JavaScript Object Notation) string
  • Ex. person: { age: 23, name: ‘john doe’ }
• The View is defined via HTML and ASP.NET code
  • <div id=“personRecord”>
     • <div id=“age”>Age: <input id=“ageValue” ></input></div>
     • <div id=“name”>Name: <input id=“nameValue” </input></div>
  • </div>
• In this scenario, the Viewmodel would bind the JSON “person”
  object to the input fields contained in the “personRecord” div
  element
  • The Viewmodel would also handle getting fresh data or sending
    updates to the server
KnockoutJS
• Open-source JavaScript MVVM library created by Steve
  Sanderson
• Simplifies the MVVM data-binding process
  • Uses “observables” to dynamically change Viewmodel properties
    upon changes to the view
  • Eliminates the need for event handlers in the UI
  • Handles retrieving and updating data from web services
• Extremely easy to learn
  • Knockoutjs.com contains a live tutorial and ample documentation
  • Very few commands to learn, yet very powerful and extendable
Example
• View
  • <p>First name: <input data-bind="value: firstName" /></p>
  • <p>Last name: <input data-bind="value: lastName" /></p>
  • <h2>Hello, <span data-bind="text: fullName"> </span>!</h2>
• ViewModel
  • function ViewModel() {
  •   this.firstName = ko.observable("Planet");
  •   this.lastName = ko.observable("Earth");
  •   this.fullName = ko.computed(function() {
  •      return this.firstName() + " " + this.lastName();
  •   }, this);
  • }
  • ko.applyBindings(new ViewModel());
• Explanation
  • The “data-bind” attribute binds an HTML element to a variable in the
    Viewmodel
  • ko.observable() tells Knockout to “observe” this variable in the View, and
    update the variable with any changes
  • ko.applyBindings() ties all declared bindings in the Viewmodel to “data-
    bind” attributes in the View
Demo
Advanced Techniques
• Mapping Data
   • ko.mapping.fromJS(data, viewModel);
• Looping
   • <ul data-bind="foreach: months">
       • <li>
           • The current item is: <b data-bind="text: $data"></b>
       • </li>
   • </ul>
• Containerless Control Flow
   • <!-- ko if: someExpressionGoesHere -->
       • <li>I want to make this item present/absent dynamically</li>
   • <!-- /ko -->
• Templating
   • <div data-bind="template: { name: 'person-template', data: seller }"></div>
   • <script type="text/html" id="person-template">
       • <h3 data-bind="text: name"></h3>
       • <p>Credits: <span data-bind="text: credits"></span></p>
   • </script>
Links
• Knockoutjs Demo Video
  • http://channel9.msdn.com/Events/MIX/MIX11/FRM08
• Knockoutjs Tutorial & Documentation
  • http://knockoutjs.com/
• MVVM
  • http://addyosmani.com/blog/understanding-mvvm-a-guide-for-
    javascript-developers/
• SharePoint 2010 REST Documentation
  • http://msdn.microsoft.com/en-us/library/ff521587.aspx
• Using the SP2010 REST Interface with JavaScript
  • http://msdn.microsoft.com/en-us/library/ff798303.aspx
Thanks!

More Related Content

What's hot

Mobile services on windows azure (part2)
Mobile services on windows azure (part2)Mobile services on windows azure (part2)
Mobile services on windows azure (part2)Radu Vunvulea
 
John Resig Beijing 2010 (English Version)
John Resig Beijing 2010 (English Version)John Resig Beijing 2010 (English Version)
John Resig Beijing 2010 (English Version)Jia Mi
 
Building web front ends using single page applications
Building web front ends using single page applicationsBuilding web front ends using single page applications
Building web front ends using single page applicationsDavid Voyles
 
Introduction to Backbone.js
Introduction to Backbone.jsIntroduction to Backbone.js
Introduction to Backbone.jsPragnesh Vaghela
 
Serverless with azure functions the rebel service
Serverless with azure functions   the rebel serviceServerless with azure functions   the rebel service
Serverless with azure functions the rebel serviceChristos Matskas
 
Building a dynamic application with GatsbyJS-Tec-Mexicali
Building a dynamic application  with GatsbyJS-Tec-MexicaliBuilding a dynamic application  with GatsbyJS-Tec-Mexicali
Building a dynamic application with GatsbyJS-Tec-MexicaliJesus Manuel Olivas
 
Backbonejs
BackbonejsBackbonejs
BackbonejsSam Lee
 
Migrating MVVM Applications to HTML5
Migrating MVVM Applications to HTML5Migrating MVVM Applications to HTML5
Migrating MVVM Applications to HTML5Chris Bannon
 
Knockout implementing mvvm in java script with knockout
Knockout implementing mvvm in java script with knockoutKnockout implementing mvvm in java script with knockout
Knockout implementing mvvm in java script with knockoutAndoni Arroyo
 
CQRS and Event Sourcing with Akka, Cassandra and RabbitMQ
CQRS and Event Sourcing with Akka, Cassandra and RabbitMQCQRS and Event Sourcing with Akka, Cassandra and RabbitMQ
CQRS and Event Sourcing with Akka, Cassandra and RabbitMQMiel Donkers
 
Robust web apps with React.js
Robust web apps with React.jsRobust web apps with React.js
Robust web apps with React.jsMax Klymyshyn
 
JsViews - Next Generation jQuery Templates
JsViews - Next Generation jQuery TemplatesJsViews - Next Generation jQuery Templates
JsViews - Next Generation jQuery TemplatesBorisMoore
 
What is j query
What is j queryWhat is j query
What is j queryCHAN DARA
 
Marketing Automation with dotCMS
Marketing Automation with dotCMSMarketing Automation with dotCMS
Marketing Automation with dotCMSJason Smith
 
Building single page apps with Durandal js
Building single page apps with Durandal jsBuilding single page apps with Durandal js
Building single page apps with Durandal jsAlex Andreu Sánchez
 
2010 - Basta!: REST mit ASP.NET MVC
2010 - Basta!: REST mit ASP.NET MVC2010 - Basta!: REST mit ASP.NET MVC
2010 - Basta!: REST mit ASP.NET MVCDaniel Fisher
 

What's hot (20)

KnockoutJS and MVVM
KnockoutJS and MVVMKnockoutJS and MVVM
KnockoutJS and MVVM
 
XAML/C# to HTML5/JS
XAML/C#  to HTML5/JS XAML/C#  to HTML5/JS
XAML/C# to HTML5/JS
 
Mobile services on windows azure (part2)
Mobile services on windows azure (part2)Mobile services on windows azure (part2)
Mobile services on windows azure (part2)
 
John Resig Beijing 2010 (English Version)
John Resig Beijing 2010 (English Version)John Resig Beijing 2010 (English Version)
John Resig Beijing 2010 (English Version)
 
Building web front ends using single page applications
Building web front ends using single page applicationsBuilding web front ends using single page applications
Building web front ends using single page applications
 
Introduction to Backbone.js
Introduction to Backbone.jsIntroduction to Backbone.js
Introduction to Backbone.js
 
Serverless with azure functions the rebel service
Serverless with azure functions   the rebel serviceServerless with azure functions   the rebel service
Serverless with azure functions the rebel service
 
Building a dynamic application with GatsbyJS-Tec-Mexicali
Building a dynamic application  with GatsbyJS-Tec-MexicaliBuilding a dynamic application  with GatsbyJS-Tec-Mexicali
Building a dynamic application with GatsbyJS-Tec-Mexicali
 
Backbonejs
BackbonejsBackbonejs
Backbonejs
 
Migrating MVVM Applications to HTML5
Migrating MVVM Applications to HTML5Migrating MVVM Applications to HTML5
Migrating MVVM Applications to HTML5
 
Knockout implementing mvvm in java script with knockout
Knockout implementing mvvm in java script with knockoutKnockout implementing mvvm in java script with knockout
Knockout implementing mvvm in java script with knockout
 
Backbone Dev Talk by Max Mamis
Backbone Dev Talk by Max MamisBackbone Dev Talk by Max Mamis
Backbone Dev Talk by Max Mamis
 
CQRS and Event Sourcing with Akka, Cassandra and RabbitMQ
CQRS and Event Sourcing with Akka, Cassandra and RabbitMQCQRS and Event Sourcing with Akka, Cassandra and RabbitMQ
CQRS and Event Sourcing with Akka, Cassandra and RabbitMQ
 
Robust web apps with React.js
Robust web apps with React.jsRobust web apps with React.js
Robust web apps with React.js
 
JsViews - Next Generation jQuery Templates
JsViews - Next Generation jQuery TemplatesJsViews - Next Generation jQuery Templates
JsViews - Next Generation jQuery Templates
 
What is j query
What is j queryWhat is j query
What is j query
 
Marketing Automation with dotCMS
Marketing Automation with dotCMSMarketing Automation with dotCMS
Marketing Automation with dotCMS
 
Asp.Net MVC
Asp.Net MVCAsp.Net MVC
Asp.Net MVC
 
Building single page apps with Durandal js
Building single page apps with Durandal jsBuilding single page apps with Durandal js
Building single page apps with Durandal js
 
2010 - Basta!: REST mit ASP.NET MVC
2010 - Basta!: REST mit ASP.NET MVC2010 - Basta!: REST mit ASP.NET MVC
2010 - Basta!: REST mit ASP.NET MVC
 

Similar to MVVM Magic in SharePoint 2010 using Knockoutjs!

MV* presentation frameworks in Javascript: en garde, pret, allez!
MV* presentation frameworks in Javascript: en garde, pret, allez!MV* presentation frameworks in Javascript: en garde, pret, allez!
MV* presentation frameworks in Javascript: en garde, pret, allez!Roberto Messora
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVC Introduction to ASP.NET MVC
Introduction to ASP.NET MVC Joe Wilson
 
What Is Angular 2 | Angular 2 Tutorial For Beginners | Angular Training | Edu...
What Is Angular 2 | Angular 2 Tutorial For Beginners | Angular Training | Edu...What Is Angular 2 | Angular 2 Tutorial For Beginners | Angular Training | Edu...
What Is Angular 2 | Angular 2 Tutorial For Beginners | Angular Training | Edu...Edureka!
 
Canopy view of single-page applications (SPAs)
Canopy view of single-page applications (SPAs)Canopy view of single-page applications (SPAs)
Canopy view of single-page applications (SPAs)Benjamin Howarth
 
Angular - Chapter 4 - Data and Event Handling
 Angular - Chapter 4 - Data and Event Handling Angular - Chapter 4 - Data and Event Handling
Angular - Chapter 4 - Data and Event HandlingWebStackAcademy
 
Planbox Backbone MVC
Planbox Backbone MVCPlanbox Backbone MVC
Planbox Backbone MVCAcquisio
 
ASP.NET MVC 5 - EF 6 - VS2015
ASP.NET MVC 5 - EF 6 - VS2015ASP.NET MVC 5 - EF 6 - VS2015
ASP.NET MVC 5 - EF 6 - VS2015Hossein Zahed
 
Integrate MongoDB & SQL data with a single REST API
Integrate MongoDB & SQL data with a single REST APIIntegrate MongoDB & SQL data with a single REST API
Integrate MongoDB & SQL data with a single REST APIEspresso Logic
 
Welcome to Wijmo 5
Welcome to Wijmo 5Welcome to Wijmo 5
Welcome to Wijmo 5Chris Bannon
 
Dynamic Application Development by NodeJS ,AngularJS with OrientDB
Dynamic Application Development by NodeJS ,AngularJS with OrientDBDynamic Application Development by NodeJS ,AngularJS with OrientDB
Dynamic Application Development by NodeJS ,AngularJS with OrientDBApaichon Punopas
 
Scalable Architectures - Microsoft Finland DevDays 2014
Scalable Architectures - Microsoft Finland DevDays 2014Scalable Architectures - Microsoft Finland DevDays 2014
Scalable Architectures - Microsoft Finland DevDays 2014Kallex
 
Valentine with Angular js - Introduction
Valentine with Angular js - IntroductionValentine with Angular js - Introduction
Valentine with Angular js - IntroductionSenthil Kumar
 
World 2013 - Pushing MicroStrategy to the Limit, The Hacker Way
World 2013 - Pushing MicroStrategy to the Limit, The Hacker WayWorld 2013 - Pushing MicroStrategy to the Limit, The Hacker Way
World 2013 - Pushing MicroStrategy to the Limit, The Hacker WayBryan Brandow
 
[Serverless Meetup Tokyo #3] Serverless in Azure (Azure Functionsのアップデート、事例、デ...
[Serverless Meetup Tokyo #3] Serverless in Azure (Azure Functionsのアップデート、事例、デ...[Serverless Meetup Tokyo #3] Serverless in Azure (Azure Functionsのアップデート、事例、デ...
[Serverless Meetup Tokyo #3] Serverless in Azure (Azure Functionsのアップデート、事例、デ...Naoki (Neo) SATO
 
Optimizing Code Reusability for SharePoint using Linq to SharePoint & the MVP...
Optimizing Code Reusability for SharePoint using Linq to SharePoint & the MVP...Optimizing Code Reusability for SharePoint using Linq to SharePoint & the MVP...
Optimizing Code Reusability for SharePoint using Linq to SharePoint & the MVP...Sparkhound Inc.
 
Yeoman AngularJS and D3 - A solid stack for web apps
Yeoman AngularJS and D3 - A solid stack for web appsYeoman AngularJS and D3 - A solid stack for web apps
Yeoman AngularJS and D3 - A solid stack for web appsclimboid
 
Learning AngularJS - Complete coverage of AngularJS features and concepts
Learning AngularJS  - Complete coverage of AngularJS features and conceptsLearning AngularJS  - Complete coverage of AngularJS features and concepts
Learning AngularJS - Complete coverage of AngularJS features and conceptsSuresh Patidar
 

Similar to MVVM Magic in SharePoint 2010 using Knockoutjs! (20)

MV* presentation frameworks in Javascript: en garde, pret, allez!
MV* presentation frameworks in Javascript: en garde, pret, allez!MV* presentation frameworks in Javascript: en garde, pret, allez!
MV* presentation frameworks in Javascript: en garde, pret, allez!
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVC Introduction to ASP.NET MVC
Introduction to ASP.NET MVC
 
What Is Angular 2 | Angular 2 Tutorial For Beginners | Angular Training | Edu...
What Is Angular 2 | Angular 2 Tutorial For Beginners | Angular Training | Edu...What Is Angular 2 | Angular 2 Tutorial For Beginners | Angular Training | Edu...
What Is Angular 2 | Angular 2 Tutorial For Beginners | Angular Training | Edu...
 
Canopy view of single-page applications (SPAs)
Canopy view of single-page applications (SPAs)Canopy view of single-page applications (SPAs)
Canopy view of single-page applications (SPAs)
 
Angular - Chapter 4 - Data and Event Handling
 Angular - Chapter 4 - Data and Event Handling Angular - Chapter 4 - Data and Event Handling
Angular - Chapter 4 - Data and Event Handling
 
Planbox Backbone MVC
Planbox Backbone MVCPlanbox Backbone MVC
Planbox Backbone MVC
 
ASP.NET MVC 5 - EF 6 - VS2015
ASP.NET MVC 5 - EF 6 - VS2015ASP.NET MVC 5 - EF 6 - VS2015
ASP.NET MVC 5 - EF 6 - VS2015
 
Integrate MongoDB & SQL data with a single REST API
Integrate MongoDB & SQL data with a single REST APIIntegrate MongoDB & SQL data with a single REST API
Integrate MongoDB & SQL data with a single REST API
 
DirectToWeb 2.0
DirectToWeb 2.0DirectToWeb 2.0
DirectToWeb 2.0
 
Welcome to Wijmo 5
Welcome to Wijmo 5Welcome to Wijmo 5
Welcome to Wijmo 5
 
Dynamic Application Development by NodeJS ,AngularJS with OrientDB
Dynamic Application Development by NodeJS ,AngularJS with OrientDBDynamic Application Development by NodeJS ,AngularJS with OrientDB
Dynamic Application Development by NodeJS ,AngularJS with OrientDB
 
Scalable Architectures - Microsoft Finland DevDays 2014
Scalable Architectures - Microsoft Finland DevDays 2014Scalable Architectures - Microsoft Finland DevDays 2014
Scalable Architectures - Microsoft Finland DevDays 2014
 
Valentine with Angular js - Introduction
Valentine with Angular js - IntroductionValentine with Angular js - Introduction
Valentine with Angular js - Introduction
 
World 2013 - Pushing MicroStrategy to the Limit, The Hacker Way
World 2013 - Pushing MicroStrategy to the Limit, The Hacker WayWorld 2013 - Pushing MicroStrategy to the Limit, The Hacker Way
World 2013 - Pushing MicroStrategy to the Limit, The Hacker Way
 
Fundaments of Knockout js
Fundaments of Knockout jsFundaments of Knockout js
Fundaments of Knockout js
 
[Serverless Meetup Tokyo #3] Serverless in Azure (Azure Functionsのアップデート、事例、デ...
[Serverless Meetup Tokyo #3] Serverless in Azure (Azure Functionsのアップデート、事例、デ...[Serverless Meetup Tokyo #3] Serverless in Azure (Azure Functionsのアップデート、事例、デ...
[Serverless Meetup Tokyo #3] Serverless in Azure (Azure Functionsのアップデート、事例、デ...
 
Optimizing Code Reusability for SharePoint using Linq to SharePoint & the MVP...
Optimizing Code Reusability for SharePoint using Linq to SharePoint & the MVP...Optimizing Code Reusability for SharePoint using Linq to SharePoint & the MVP...
Optimizing Code Reusability for SharePoint using Linq to SharePoint & the MVP...
 
Html5 css3 Online Training
Html5 css3 Online Training Html5 css3 Online Training
Html5 css3 Online Training
 
Yeoman AngularJS and D3 - A solid stack for web apps
Yeoman AngularJS and D3 - A solid stack for web appsYeoman AngularJS and D3 - A solid stack for web apps
Yeoman AngularJS and D3 - A solid stack for web apps
 
Learning AngularJS - Complete coverage of AngularJS features and concepts
Learning AngularJS  - Complete coverage of AngularJS features and conceptsLearning AngularJS  - Complete coverage of AngularJS features and concepts
Learning AngularJS - Complete coverage of AngularJS features and concepts
 

Recently uploaded

Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 

Recently uploaded (20)

Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 

MVVM Magic in SharePoint 2010 using Knockoutjs!

  • 1. MVVM magic in SharePoint 2010 using KnockoutJS! Ajay Nayak Cap Area SharePoint SIG 08/14/2012
  • 2. About Me • SharePoint “jack of all trades” • Booz Allen Hamilton • 5 years working exclusively with SharePoint 2003/2007/2010 • Things that excite me: • Well-constructed SharePoint solutions • HTML5 • Mountain biking • Craft beer • @ajaynayak • ajaynayak {at} gmail {dot} com
  • 3. Client-side Development • Coding on the client (HTML, JavaScript, CSS) vs. the server (.NET, Java) • Modern browsers combined with new standards (HTML5) and powerful frameworks (jQuery) • Users have come to expect asynchronous operations and rich UI interaction
  • 4. What about SharePoint? • Client-side tools at our disposal • SP2010 client-side object model • SPServices library • REST web services to interact with • Reasons for developing client-side applications • Easy to deploy • Simple as pushing element files into document libraries • “Cloud ready” • The SP2013 “Cloud App Model” encourages JS on the client and RESTful services in the cloud
  • 5. The Dilemma… • How do we manage the interaction between HTML, JavaScript, CSS, and web services? • jQuery provides us a powerful framework, but how do we structure our app in a way that preserves functionality, but reduces “code bloat”?
  • 6. Model-View-Viewmodel • Architectural pattern created by Microsoft for WPF development • Separates UI from the Data layer and Business Logic • Model • Defines the objects • View • Defines the user interface • Viewmodel • Defines how the user interface (View) is integrated with the data (Model)
  • 7. Common MVVM Scenario • The Model is defined server-side and is sent to the client in the form of a JSON (JavaScript Object Notation) string • Ex. person: { age: 23, name: ‘john doe’ } • The View is defined via HTML and ASP.NET code • <div id=“personRecord”> • <div id=“age”>Age: <input id=“ageValue” ></input></div> • <div id=“name”>Name: <input id=“nameValue” </input></div> • </div> • In this scenario, the Viewmodel would bind the JSON “person” object to the input fields contained in the “personRecord” div element • The Viewmodel would also handle getting fresh data or sending updates to the server
  • 8. KnockoutJS • Open-source JavaScript MVVM library created by Steve Sanderson • Simplifies the MVVM data-binding process • Uses “observables” to dynamically change Viewmodel properties upon changes to the view • Eliminates the need for event handlers in the UI • Handles retrieving and updating data from web services • Extremely easy to learn • Knockoutjs.com contains a live tutorial and ample documentation • Very few commands to learn, yet very powerful and extendable
  • 9. Example • View • <p>First name: <input data-bind="value: firstName" /></p> • <p>Last name: <input data-bind="value: lastName" /></p> • <h2>Hello, <span data-bind="text: fullName"> </span>!</h2> • ViewModel • function ViewModel() { • this.firstName = ko.observable("Planet"); • this.lastName = ko.observable("Earth"); • this.fullName = ko.computed(function() { • return this.firstName() + " " + this.lastName(); • }, this); • } • ko.applyBindings(new ViewModel()); • Explanation • The “data-bind” attribute binds an HTML element to a variable in the Viewmodel • ko.observable() tells Knockout to “observe” this variable in the View, and update the variable with any changes • ko.applyBindings() ties all declared bindings in the Viewmodel to “data- bind” attributes in the View
  • 10. Demo
  • 11. Advanced Techniques • Mapping Data • ko.mapping.fromJS(data, viewModel); • Looping • <ul data-bind="foreach: months"> • <li> • The current item is: <b data-bind="text: $data"></b> • </li> • </ul> • Containerless Control Flow • <!-- ko if: someExpressionGoesHere --> • <li>I want to make this item present/absent dynamically</li> • <!-- /ko --> • Templating • <div data-bind="template: { name: 'person-template', data: seller }"></div> • <script type="text/html" id="person-template"> • <h3 data-bind="text: name"></h3> • <p>Credits: <span data-bind="text: credits"></span></p> • </script>
  • 12. Links • Knockoutjs Demo Video • http://channel9.msdn.com/Events/MIX/MIX11/FRM08 • Knockoutjs Tutorial & Documentation • http://knockoutjs.com/ • MVVM • http://addyosmani.com/blog/understanding-mvvm-a-guide-for- javascript-developers/ • SharePoint 2010 REST Documentation • http://msdn.microsoft.com/en-us/library/ff521587.aspx • Using the SP2010 REST Interface with JavaScript • http://msdn.microsoft.com/en-us/library/ff798303.aspx