Professional Documents
Culture Documents
Musician
Developer
Father
SharePointian
Federal Team
SharePoint Developer Planet Technologies
MVVM in brief
Knockout overview
SharePoint REST overview
Connecting the Dots
What is it?
Separation of powers/interests
Model
Holds the information
Independent of UI
View
Formats the information
State representation of the view model
ViewModel
Encapsulates behavior
Code representation of data and operations
Overview
JavaScript Library
Free, Open Source
<input type="text"/>
<input type="checkbox"/>
<select> </select>
Copyright: 2008 Columbia Pictures. All Rights Reserved.
Simple binding
(VIEWMODEL)
<script type="text/javascript">
var Person = function () {
var self = this;
this.FirstName = ko.observable("Dale");
this.LastName = ko.observable("Doback");
this.Specialty = ko.observable("Research and Development");
}
var myRep = new Person();
ko.applyBindings(myRep);
</script>
New in 2013
http://<site>/_api/
Data operation
GET
Retrieve
POST
Create
PUT
DELETE
Delete
MERGE
$metadata
Shows data entity model for every list in site
$orderby
Sorts by Property
/listdata.svc/{listname}?$orderby=Title desc
$select
Bring back only what you need
/listdata.svc/{listname}?$select=Title, ID
$expand
Returns related data inline (Joins)
/listdata.svc/{listname}?$expand=Specialty
$filter
Filters by Property (works for lookup properties as well)
/listdata.svc/{listname}?$filter=Title eq Some Value
/listdata.svc/{listname}?$filter=Specialty/Title eq
Business
ViewModel
self.AddRepresentative = function () {
alert('You want to add ' + self.FirstName() + ' ' +
self.LastName());
}
$.ajax({
type: 'POST',
url: url,
contentType: 'application/json',
processData: false,
data: ko.toJSON(myPerson),
success: function () {
alert('You added ' + self.FirstName() + ' ' + self.LastName());
}
});
<script type="text/javascript">
var dispVm = {
results: ko.observable(),
};
ko.applyBindings(dispVm, document.getElementById('divDisplay'));
</script>
(function poll() {
$.ajax({
url: _spPageContextInfo.webServerRelativeUrl +
"_vti_bin/listdata.svc/Representatives?$expand=Specialty",
success: function (data) {
//Update the Display
dispVm.results(data.d.results);
}, dataType: "json", complete: poll, timeout: 30000
});
})();
Controlling text
and appearance
The visible binding
The text binding
Control flow
The foreach binding
The if binding
The ifnot binding
The with binding
Rendering
templates
The template
binding
Experiment
Write custom WCF Services
Web Parts
http://bit.ly/spsbmorexlg
Thank you!