2014-08-31 134 views
2

我想運行一個簡單的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'); 

回答

5

可能發生指定的錯誤的followi的由於一個NG原因:

  1. 色譜柱的內部名稱Value在列表Configuration Values

    由於SP.ListItem.item property存在期望場內部名稱,請確保領域這樣的名字在名單中存在。

  2. 無法隱式加載字段Value的列表項值。

    解決方案:嘗試明確指定使用SP.ClientContext.load method加載的 的列表項屬性。將行:與

    context.load(collListItems,'Include(Title,Value)'); 
    
+0

就我而言,我不得不打開了ConfigurationValues列表中的Schema.xml文件。我注意到給出的內部名稱是「Value1」,而不是「Value」。將腳本更改爲使用Value1或列表內部名稱爲Value fixed。 – danludwig 2014-11-24 17:55:07

0

context.load(collListItems); 

App.js文件更改ValueValue1,它會正常工作適合你,如果沒有,那麼請點擊值字段中配置值列表並檢查URL中的內部名稱,在這裏您可以找到您的列值的確切內部名稱。 See internal name of the Value field

OrgName = oListItem.get_item('Value1'); 

enter image description here

相關問題