2017-02-23 44 views
0

我想在啓動時爲我的UWP-JS應用程序創建設置值。
我關注此DocumentationUWP:如何訪問ApplicationData

以下是我目前有:

(function() { 
    "use strict" 

    //Initialization 
    var localSettings = Windows.Storage.ApplicationData.current.localSettings; 
    // Save value 
    localSettings.Values["exampleSetting"] = "example"; 
    // Retrieve value 
    $('p').text(localSettings.Values["exampleSetting"]); 
})(); 

當我開始進入「休息模式」具有以下異常在給定的代碼的7號線的應用:

0x800a138f - JavaScript runtime error: Unable to set property 'exampleSetting' of undefined or null reference


我在做什麼錯?

+1

屬性是camelCase,所以'Values'應該是'values'。這遵循常見的JS約定。 –

回答

1

您錯過了current屬性,這在您參考的示例中也有提及。所以,你的電話應該是:

編輯
(function() { 
    "use strict" 

    //Initialization 
    var localSettings = Windows.Storage.ApplicationData.current.localSettings; 
    // Save value 
    localSettings.values["exampleSetting"] = "example"; 
    // Retrieve value 
    $('p').text(localSettings.values["exampleSetting"]); 
})(); 


的屬性和方法的名稱後Windows.Storage.ApplicationData需要用小寫字母開始。

+0

是的,我已經嘗試過,並給了我以下錯誤:'0x800a138f - JavaScript運行時錯誤:無法獲取未定義或空引用的屬性'LocalSettings' – jonhue

+0

@jonhue請參閱我的編輯。這只是一個小寫的問題。但仍然需要調用'current' – TheTanic

+0

Infact我現在得到以下錯誤:'0x800a138f - JavaScript運行時錯誤:無法設置屬性'exampleSetting'的未定義或空引用' – jonhue