I'm fairly new to the JavaScript Object Model (JSOM) and I want to do a simple call to get a field value. Very easy in C#, but I can't seem to get a field value even though I have the ListItem:
overrideContext.Templates.Item = customItem;
function customItem(context) {
var title = context.CurrentItem["Title"];
var img = "<img src='" + getImageUrl(1) + "' />";
return title + img;
function getImgUrl(classID) {
var clientContext = new SP.ClientContext();
var web = clientContext.get_web();
var sourceList = web.get_lists().getByTitle('ClassifiedImages');
var listItem = sourceList.getItemById(classID);
clientContext.load(listItem);
clientContext.executeQueryAsync(Function.createDelegate(this, function () { _returnParam = onSuccess(); }), Function.createDelegate(this, function () { _returnParam = onFail(); }));
return _returnParam;
}
I don't want to use an Async execution. I need the value to be returned immediately. Since I have the listItem, why can't I just say return listItem["Title"]; ??