I have used below code for getting list items from SharePoint list. Output is coming in alerts but it is not displayed in HTML controls.
<html lang="en-US">
<head>
<meta charset="UTF-8">
</head>
<script src="http://ajax.aspnetcdn.com/ajax/knockout/knockout-2.2.1.js" type="text/javascript"></script>
<script src="http://code.jquery.com/jquery-1.7.1.js"></script>
<script>
function insightViewModel() {
var self = this;
self.insights = ko.observableArray();
$.ajax({
url: "http://demo/Dev/_api/web/lists/getbytitle('CountryNames')/items",
type: "GET",
headers: {
"accept": "application/json;odata=verbose",
},
success:suc,
error: function (error) {
alert(JSON.stringify(error));
}
});
function suc(data)
{
alert(data.d.results);
r=data.d.results;
alert(r[1].CountryName);
for(var i=0;i<5;i++)
{
self.insights.push({
Title:ko.observable(r[i].Title),
CountryName:ko.observable(r[i].CountryName)
});
alert(r[i].CountryName);
}
}
}
ko.applyBindings(new insightViewModel());
</script>
<body>
<table>
<thead>
<tr><th>Title</th><th>Name</th></tr>
</thead>
<tbody data-bind="foreach:insights">
<tr>
<td data-bind="text:CountryName"></td>
</tr>
</tbody>
</table>
</body>
</html>
This is the output of data.d.results from sharepoint site. I have used this code in script editor.
