2017-01-04 1 views
0

Visual Studio에서 다음 코드를 사용하고 있습니다. 바탕 화면 win10의 UWP 응용 프로그램이 내 Windows Phone에서 UWP 응용 프로그램으로 작동하지 않지만 완벽하게 작동합니다. 나는 또한 웹 서버에서 내 간단한 웹 응용 프로그램을 실행하고 가장자리에로드하려고 노력하고 완벽하게 작동합니다. 무엇이 문제인가? 내 코드는 다음과 같습니다. 에 MS-appx - 웹 라인 (28)에 처리되지 않은 예외, 열 25 : : 나는 SAIS 내 장치에서이 콘드을 RUND 때 지금정의되지 않은 또는 null 참조의 속성을 얻을 수 없습니다. UWP

var model = { 
    db: {}, 
    goalsobj: {}, 
    goals: [], 
    init: function() { 
     var openReq = window.indexedDB.open("GoalsDB"); 
     openReq.onupgradeneeded = function (event) { 
      model.db = event.target.result; 
      var objectStore = model.db.createObjectStore("Goals", { keyPath: "id" }); 
      objectStore.createIndex("id","id", {unique:true}); 
     }; 
     openReq.onsuccess = function (event) { 
      model.db = event.target.result 
      model.db.transaction("Goals", "readonly").objectStore("Goals").count().onsuccess = function (event) { 
       if (event.target.result == 0) { 
        console.log("indexeddb empty"); 
        var goalstemplate = { 
         id: "idee", 
         goals: [{ "name": "Task1" }, { "name": "Task2" }, { "name": "Task3" }] 
         } 
        var addReq = model.db.transaction("Goals", "readwrite").objectStore("Goals").add(goalstemplate); 
       } else { 
        model.db.transaction("Goals", "readonly").objectStore("Goals").get("idee").onsuccess = function (e) { 
         model.goalsobj = e.target.result; 
         //console.log(e.target.result); 
         model.goals = model.goalsobj.goals; 
         goalfunc.makeList(); //model should not talk to view, but this case it is amust, because if I remove this, it does not render at boot. 
         } 

       } 

      } 
    openReq.onerror = function (event) { 
     console.log("Operation failed"); 
    } 

} 
    }, 
    add: function(goalname) { 
     model.goals.push(
      { 
       "name": goalname 
     }); 
     model.savedb(); 
    }, 
    move: function (id,updown) { 
     if (updown == "up") { 
      model.goals.splice((id-1), 0, model.goals.splice(id, 1)[0]); 
     }; 
     if (updown == "down") { 
      model.goals.splice((id+1), 0, model.goals.splice(id, 1)[0]); 
     }; 
    }, 
    savedb: function(){ 
     //console.log(goals); 
     var update = model.db.transaction("Goals", "readwrite").objectStore("Goals").put(model.goalsobj); 
     update.onerror = function (event) { 
      console.log(event); 
     }; 

}, 
}; 

: 나는 일부를 생략 // 1318f74a-397e-4958-aa6b- c8d11b7c5dce/JS/main.js

0x800a138f - 자바 스크립트 런타임 오류 : 정의되지 않았거나 null 참조의 특성 '목표'를 가져올 수 없습니다

답변

0
내 장치에서 코드를 테스트 한

(장치 : 마이크로 소프트 RM-1118 OSVERSION : WindowsMobile 14393). 잘 작동합니다. 보시다시피 html 페이지에 단추를 놓았습니다. 버튼 클릭 동작은 model.init()을 실행 한 다음 중단 점을 model.goals = model.goalsobj.goals;에 설정합니다. 버튼을 다시 클릭하면 model.goals이 올바른 값으로 설정됩니다.

그래서이 문제는 대상 장치에서 발생하거나 GoalsDB이 파괴 된 것 같습니다. Unable to get property 'goals' of undefined or null reference의 원인은 model.goalsobj이 올바른 값으로 설정되지 않았기 때문입니다. 해당 작업으로 인해 데이터베이스 구조가 변경되었는지 (예 : 이동 작업) 확인하십시오. 대상 장치에 대한 자세한 내용을 표시 할 수 있으며 도움을 드릴 것입니다.

(function() { 
    document.getElementById("createDatabase").addEventListener("click", createDB, false); 
    function createDB() { 
     model.init(); 
    } 
})(); 
var model = { 
    db: {}, 
    goalsobj: {}, 
    goals: [], 
    init: function() { 
     var openReq = window.indexedDB.open("GoalsDB"); 
     openReq.onupgradeneeded = function (event) { 
      model.db = event.target.result; 
      var objectStore = model.db.createObjectStore("Goals", { keyPath: "id" }); 
      objectStore.createIndex("id", "id", { unique: true }); 
     }; 
     openReq.onsuccess = function (event) { 
      model.db = event.target.result 
      model.db.transaction("Goals", "readonly").objectStore("Goals").count().onsuccess = function (event) { 
       if (event.target.result == 0) { 
        console.log("indexeddb empty"); 
        var goalstemplate = { 
         id: "idee", 
         goals: [{ "name": "Task1" }, { "name": "Task2" }, { "name": "Task3" }] 
        } 

        model.db.transaction("Goals", "readwrite").objectStore("Goals").add(goalstemplate); 

       } else { 
        model.db.transaction("Goals", "readonly").objectStore("Goals").get("idee").onsuccess = function (e) { 

         model.goalsobj = e.target.result; 
         //console.log(e.target.result); 
         if (model.goalsobj.goals != undefined) { 
          model.goals = model.goalsobj.goals; 
         } else { 
          console.log(e.target.result); 
         } 

         //goalfunc.makeList(); //model should not talk to view, but this case it is amust, because if I remove this, it does not render at 
        } 
       } 
      } 
      openReq.onerror = function (event) { 
       console.log("Operation failed"); 
      } 
     } 
    }, 
    add: function (goalname) { 
     model.goals.push(
      { 
       "name": goalname 
      }); 
     model.savedb(); 
    }, 
    move: function (id, updown) { 
     if (updown == "up") { 
      model.goals.splice((id - 1), 0, model.goals.splice(id, 1)[0]); 
     }; 
     if (updown == "down") { 
      model.goals.splice((id + 1), 0, model.goals.splice(id, 1)[0]); 
     }; 
    }, 
    savedb: function() { 
     //console.log(goals); 
     var update = model.db.transaction("Goals", "readwrite").objectStore("Goals").put(model.goalsobj); 
     update.onerror = function (event) { 
      console.log(event); 
     }; 
    } 
}; 
+0

감사합니다! 나는 다른 장치를 얻을 수 있었고 잘 작동합니다. – Peter

관련 문제