页面是一个对象:
page= new function(img_data_url, src, pos_x, pos_y)
{
this.ImgDataURL= img_data_url;
this.src= src;
this.pos_x= pos_x;
this.pos_y= pos_y;
}
我创建了一个XML
格式来记录其详细信息。
在一个编辑过的页面中,有几个“邮票”,我有几个“页面”。
<Page pid= "0">
<ImgDataURL>asjdfklsadsadfasdf</ImgDataURL>
<Stamp>
<src src="../pic/XXX">
<pos_x>123</pos_x>
<pos_y>123</pos_y>
</src>
<src src="../pic/XXO">
<pos_x>456</pos_x>
<pos_y>123</pos_y>
</src>
</Stamp>
</Page>
<Page pid= "1">
<ImgDataURL>asjdfklsadsadfasdf</ImgDataURL>
<Stamp>
<src src="../pic/XXX">
<pos_x>123</pos_x>
<pos_y>123</pos_y>
</src>
<src src="../pic/XXO">
<pos_x>456</pos_x>
<pos_y>123</pos_y>
</src>
</Stamp>
</Page>
<Page pid= "2">
<ImgDataURL>asdfsdfasd</ImgDataURL>
<Stamp>
<src src="../pic/XXX">
<pos_x>123</pos_x>
<pos_y>123</pos_y>
</src>
<src src="../pic/XXO">
<pos_x>456</pos_x>
<pos_y>123</pos_y>
</src>
</Stamp>
</Page>
我想在ImgDataURL
文件中检索信息:src of Stamp
,pos_x of Stamp
,pos_y of Stamp
,XML
,并将它们分配回对象。
但是在第一步中,我不知道如何通过属性选择页面:使用jQuery“pid”。
(Or should I have better alternative approaches instead of giving it an id?)
第二,如何获取内容中的所有内容
邮票标签:src
,position
等等......
在决赛中:
Any well-designed alternative XML structure is acceptable.
毕竟,我的目的是将信息存储在文件中并将它们带回内存。我希望操纵可以尽可能简单。
答案 0 :(得分:0)
将json对象保存在.json文件中(如果在服务器上使用php,则可以使用json_encode)
pages = {
'0' : {
'ImgDataURL' : 'whatever'
,Stamp : {
src : 'whatefcz'
,pos_x : 'cdscsdc'
}
},
'1' : {
'ImgDataURL' : 'whatever'
,Stamp : {
src : 'whatefcz'
,pos_x : 'cdscsdc'
}
},
...
}
您可以直接在javascript中访问它
pages['0'].Stamp.src
您可以通过在脚本之前将其包含在脚本标记中,或者在加载jquery之后使用getJSON调用服务器来加载它