简体   繁体   English

如何保存动态对象的状态(不包含在html中)

[英]how to save the state of dynamic objects (not included in html)

I'm doing a project that involves placing a shape onto a canvas and saving its state to be viewed in another session. 我正在做一个项目,其中涉及将形状放在画布上并保存其状态以在另一个会话中查看。 Since the shape's color and location are not a part of the source HTML nor are they provided by a form, how can i save it? 由于形状的颜色和位置不是源HTML的一部分,也不由表单提供,因此如何保存? I've tried storing the shape's data inside an object and then an array, but i dont know how to retrieve this information in another session. 我试过将形状的数据存储在对象中,然后存储在数组中,但是我不知道如何在另一个会话中检索此信息。 Here is the code for the shape: 这是形状的代码:

var shapeState = { //Example of a shape being recorded
                            number:increment,
                            id:thisCanvas,
                            type:'shape',
                            kind:shapeKind,
                            cheight:canvasHeight,
                            cwidth:canvasWidth,
                            height:shapeHeight,
                            width:shapeWidth,
                            color:shapeColor,
                            x:xPos,
                            y:yPos
                        }

                        totalState.push(shapeState); //State of shape data has been stored in global array

Can anyone help? 有人可以帮忙吗? The fiddle for the entire project is here: http://jsfiddle.net/RymyY/5/ 整个项目的小提琴在这里: http : //jsfiddle.net/RymyY/5/

Modern browsers support the web storage API ; 现代浏览器支持Web存储API ; for older ones, you'd use cookies. 对于较旧的,则使用Cookie。 jQuery has a number of storage plugins that abstract away the specific storage mechanism. jQuery有许多存储插件可以抽象出特定的存储机制。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM