If somebody like the post and its helpful in your work then, add comments.

Tuesday, October 8, 2013

SharePoint 2013 : Get SharePoint items in Knockout js observableArray

To get the list tem in the observableArray, just declare a array in the js and get as below code

list = ko.observableArray(),


 getCourses = function () {
var
clientContext = TRANAPP.context;
var oList = clientContext.get_web().get_lists().getByTitle('Courses'
);
var myQueryString = '<View><RowLimit>1000</RowLimit></View>'
;
var newQuery = new
SP.CamlQuery();
newQuery.set_viewXml(myQueryString);
courseItems = oList.getItems(newQuery);
clientContext.load(courseItems,
'Include(Id, Title, CourseDescription, Author)'
);
clientContext.executeQueryAsync(onGettingCourses, onQueryFailed);
},
onGettingCourses =
function
(sender, args) {
var
allCourse = courseItems.getEnumerator();
while
(allCourse.moveNext()) {
var
currentCourse = allCourse.get_current();
list.push({
"Title": currentCourse.get_item('Title'
),
"Id"
: currentCourse.get_id(),
"CourseDescription": currentCourse.get_item('CourseDescription'
)
});
}
},
onQueryFailed = function (sender, args) {
alert(
'Request failed. ' + args.get_message() + '\n'
+ args.get_stackTrace());
},

No comments:

Post a Comment