none
Binding SharePoint list data with Knockout js using REST API in O365 RRS feed

  • Question

  • Hi,

    I am trying to bind data of SharePoint list using REST API and Knockout js in 0365.

    I am getting error "Unable to bind observable- Title is not defined"

    This is my javascript code:              

    <script>
    function insightViewModel() {
        var self = this;
        self.insights = ko.observableArray([]);
        $.ajax({
                    url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('EmployeeDetailsList')/items?$select=Title,uu8e,EmployeeId",
                    type: "GET",
                    headers: {
                        "accept": "application/json;odata=verbose",
                    },
                    success:success,
                    error: function (error) {
                        alert(JSON.stringify(error));
                        }
                    });
        function success(data) {
    alert(data.d.results[0].Title + " - " + data.d.results[0].EmployeeId);
               self.insights.push(data.d.results); 
        }
    }
    $(document).ready(function() {
      ko.applyBindings(new insightViewModel());
    });
    </script>

    And this my HTML code:

    <tbody data-bind="foreach: insights">
          <tr>
             <td data-bind="text: Title">
             </td>
             <td data-bind="text: EmployeeId">
             </td>
          </tr>
       </tbody>

    Thursday, April 13, 2017 6:43 PM

All replies