我试图在一个简单的sharepoint应用程序中运行以下代码,但是我收到了这个错误:
Uncaught Error: The property or field has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.
代码就是这个:
var collListItems;
$(document).ready(function () {
getConfigValues();
});
function getConfigValues() {
var context = SP.ClientContext.get_current();
var configList = context.get_web().get_lists().getByTitle('Configuration Values');
var camlQuery = new SP.CamlQuery();
collListItems = configList.getItems(camlQuery);
context.load(collListItems);
context.executeQueryAsync(onGetConfigValuesSuccess, onGetConfigValuesFail);
}
function onGetConfigValuesSuccess() {
var OrgLogoUrl;
var OrgName;
var listItemEnumerator = collListItems.getEnumerator();
while (listItemEnumerator.moveNext()) {
var oListItem = listItemEnumerator.get_current();
var current = oListItem.get_item('Title');
switch (current) {
case 'OrganizationName':
OrgName = oListItem.get_item('Value');
break;
case 'OrganizationLogoUrl':
OrgLogoUrl = oListItem.get_item('Value');
break;
};
}
if (OrgName && OrgName.length > 0) {
$('#DeltaPlaceHolderPageTitleInTitleArea').html(OrgName);
$('.ms-siteicon-img').attr('title', OrgName);
}
if (OrgLogoUrl && OrgLogoUrl.length > 0)
$('.ms-siteicon-img').attr('src', OrgLogoUrl);
else
$('.ms-siteicon-img').attr('src', '../Images/AppLogo.png');
}
function onGetConfigValuesFail(sender, args) {
alert('Failed to get the Configuration Values. Error:' + args.get_message());
}
代码来自一本书,没有任何修改:
OrgName = oListItem.get_item('Value');
答案 0 :(得分:6)
由于以下原因之一,可能会发生指定的错误:
内部名称为Value
的列在列表Configuration Values
中存在不
由于SP.ListItem.item property需要字段内部名称,请确保列表中存在具有此名称的字段。
无法隐式加载字段Value
的列表项值。
解决方案:尝试明确指定List Item属性 使用SP.ClientContext.load method加载。替换行:
context.load(collListItems);
与
context.load(collListItems,'Include(Title,Value)');
答案 1 :(得分:0)