Showing posts from January, 2015

Knockout binding in SharePoint 2013 SharePoint-Hosted App

Today I was trying to make Knockoutjs work with SharePoint Hosted Apps in a way that is manageable and extensible. I assume you already know Knockout JS and know how to create a basic SharePoint-Hosted App.

There can be many ways using which KO can be plugged into an application but here here is what I think would work well for SharePoint-Hosted Apps considering async JSOM calls:

Step1: Add Knockout JS
Just download the js file and paste inside the Scripts folder. Refer it in your Default.aspx page.

Step2: Add html binding
In the Default.aspx page of SharePoint 2013 Hosted put the following code in the "<p id="message">" tag:
Welcome <span data-bind="text: username"></span>Step3: Apply KO Bindings
At the bottom of the Default.aspx page put the following code:
    <script >
        var viewModel = new window.MyApp.ViewModel();
    </script>Step4: Your App Module
In the …