简体   繁体   English

IndexedDB错误:未捕获的DataCloneError:无法在“ IDBObjectStore”上执行“ put”:无法克隆对象

[英]IndexedDB error: Uncaught DataCloneError: Failed to execute 'put' on 'IDBObjectStore': An object could not be cloned

I am using the Google maps API along with the HTML 5 geolocation API to display my position as a marker on a map. 我正在使用Google Maps API和HTML 5 geolocation API来将我的位置显示为地图上的标记。 Once this marker is displayed I have a simple on marker double click function that saves a new marker to my current position using indexedDB. 一旦显示了该标记,我便有了一个简单的标记双击功能,该功能可以使用indexedDB将新标记保存到当前位置。 Everything goes well until the Object is about to be stored, then I recieve the message " Uncaught DataCloneError: Failed to execute 'put' on 'IDBObjectStore': An object could not be cloned. " in the console. 一切顺利,直到将要存储对象为止,然后在控制台中收到消息“ Uncaught DataCloneError:无法在'IDBObjectStore'上执行'put':无法克隆对象。 ”。 my code is as follows: 我的代码如下:

        function initialize() {
          var mapProperties = { // Set the maps properties
            center:new google.maps.LatLng(55.8580,-4.2590),
            zoom:8,
            mapTypeId:google.maps.MapTypeId.ROADMAP
          };    

          var map=new google.maps.Map(document.getElementById("map-overview"),mapProperties);   //Display the map in the map-overview div








          function NogeoLocation(e) {   //A function to handle users that do not have Geolocation
          if (e) {
            var content = 'Error: Unfortunately the Geolocation service failed.';
          } else {
            var content = 'Error: Sorry, Your web browser doesn\'t support geolocation.';
          }

            var options = { //Error options
            map: map,
            position: new google.maps.LatLng(60, 105), //Set new position on Error
            content: content    //Display error message
          };

          var infowindow = new google.maps.InfoWindow(options); 
          map.setCenter(options.position);


         }  


           //Using HTML5 Geolocation
          if(navigator.geolocation) {
            navigator.geolocation.getCurrentPosition(function(position) {
              var position = new google.maps.LatLng(position.coords.latitude,
                                               position.coords.longitude);







            var contentString = "Here is your current location!" + "<button onclick='myBtn()'>Save</button>"

             var infowindow = new google.maps.InfoWindow({
              content: contentString
          });


          var marker = new google.maps.Marker({
              position: position,
              map: map,
              title: 'My House'
          });




            google.maps.event.addListener(marker, 'click', function() {
            infowindow.open(map,marker);
          });

        var db;

        function indexedDBOk() {
            return "indexedDB" in window;
        }

        google.maps.event.addListener(marker, 'dblclick', function() {

        alert("dbl Click");

        console.log(position);



            if(!indexedDBOk) return;

            var openRequest = indexedDB.open("idarticle_people",1);

            openRequest.onupgradeneeded = function(e) {
                var thisDB = e.target.result;

                if(!thisDB.objectStoreNames.contains("people")) {
                    thisDB.createObjectStore("people");
                }
            }

            openRequest.onsuccess = function(e) {
                console.log("running onsuccess");

                db = e.target.result;




            var transaction = db.transaction(["people"],"readwrite");
            var store = transaction.objectStore("people");

            //Define a marker
             var marker = {
             position: position,
             map: map,
            title: 'New Marker'
         }
         console.log(marker);
         console.log("about to perform add");
            //Perform the add
            var request = store.put(marker,1);

            console.log("added");

            request.onerror = function(e) {
                console.log("Error",e.target.error.name);
                //some type of error handler
            }

            request.onsuccess = function(e) {
                console.log("Woot! Did it");
            }



            }

            openRequest.onerror = function(e) {
                //Do something for the error
            }





        });













              map.setCenter(position);
            }, function() {
              NogeoLocation(true); // Refers to NogeoLocation function
            });
          } else {
            // If the user's browser doesn't support Geolocation
            NogeoLocation(false);
          } //End of HTML5 GeoLocation










          } // End of the function that initializes Google Maps


        google.maps.event.addDomListener(window, 'load', initialize);   //On page load, execute initialize()

marker can't be cloned because the object stored in the map -property contains a reference to a DOMNode( #map-overview ), which can't be cloned (see: T hings that don't work with structured clones ). marker不能被克隆,因为存储在map -property中的对象包含对DOMNode( #map-overview )的引用,该引用不能被克隆(请参阅: 不适用于结构化克隆的 )。

Remove the map -property, it will not be re-usable at all because the google.maps.Map -instance will not exist when you retrieve the marker later. 删除map属性,因为它在以后检索标记时google.maps.Map -instance将不存在,因此将根本无法重复使用。

I discovered that the reason for the error was to try to add an object that was not recognized to a cache. 我发现该错误的原因是试图将无法识别的对象添加到缓存中。

this.storage.set ("page", HomePage); this.storage.set(“页面”,主页);

I switched to a string and it worked 我切换到一个字符串,它起作用了

this.storage.set ("page", "HomePage"); this.storage.set(“页面”,“主页”);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法在“ IDBObjectStore”上执行“ put”:无法克隆对象 - Failed to execute 'put' on 'IDBObjectStore': An object could not be cloned IndexedDB 错误:无法克隆 IDBObjectStore 符号 - IndexedDB error: IDBObjectStore Symbol could not be cloned ReactJS DataCloneError:无法在“历史”上执行“pushState”:无法克隆 MouseEvent object - ReactJS DataCloneError: Failed to execute 'pushState' on 'History': MouseEvent object could not be cloned DataCloneError:无法克隆对象 - DataCloneError: An object could not be cloned DataCloneError:无法克隆对象 - DataCloneError: The object could not be cloned javascript 将 function object 传递给 web 工作人员 - 可能无法克隆错误 DataCloneError - javascript passing a function object to a web worker - ERROR DataCloneError could not be cloned 未捕获的 DOMException:无法在“Window”上执行“postMessage”:无法克隆对象 - Uncaught DOMException: Failed to execute 'postMessage' on 'Window': An object could not be cloned 错误并且没有相同代码的错误:无法在&#39;IDBObjectStore&#39;上执行&#39;put&#39; - Error and no error with the same code: Failed to execute 'put' on 'IDBObjectStore' “DataCloneError:无法克隆对象。” 在 Firefox 34 - “DataCloneError: The object could not be cloned.” in FireFox 34 未捕获的 DOMException:无法在“IDBObjectStore”上执行“放置”:评估 object 存储的密钥路径在 request.onsuccess 处未产生值 - Uncaught DOMException: Failed to execute 'put' on 'IDBObjectStore': Evaluating the object store's key path did not yield a value at request.onsuccess
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM