我想运行一个简单的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');
就我而言,我不得不打开了ConfigurationValues列表中的Schema.xml文件。我注意到给出的内部名称是“Value1”,而不是“Value”。将脚本更改为使用Value1或列表内部名称为Value fixed。 – danludwig 2014-11-24 17:55:07