我正在尝试使用 jqwidgets 构建一个侧边栏导航菜单,但似乎无法弄清楚如何填充它,因为我是一个 javascript 菜鸟。
我有以下 json 数据结构:
{
"scenes": {
"Imagem1": {
"title": "Imagem1",
"hfov": 120,
"pitch": -12,
"yaw": 180,
"type": "equirectangular",
"panorama": "http://my.ip.address/images/20170114-152411.jpg",
"hotSpotDebug": true,
"autoLoad": true,
"autoRotate": 2,
"hotSpots": [
{
"pitch": -5,
"yaw": -125,
"type": "scene",
"text": "Imagem2",
"sceneId": "Imagem2"
}
]
},}
我希望能够从图像名称(取自上面的全景字段)构建(我认为是标记?)树结构。就像是:
2017--->January--->Saturday 14--->Title
我正在尝试使用 getjson 并且可以正确提取数据。尽管如此,我无法创建填充 jqxtree 所需的必要结构。
$.getJSON('/my.json',{},function(data) {
for (item in data) {
for (subItem in data[item]) {
var mbase = data[item][subItem];
console.log(mbase.panorama);
}
}});
我可以使用我在 www 某处找到的这个函数来解析日期。
function parse (str) {
// validate year as 4 digits, month as 01-12, and day as 01-31
if ((str = str.match (/^(\d{4})(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])$/))) {
// make a date
str[0] = new Date (+str[1], +str[2] - 1, +str[3]);
// check if month stayed the same (ie that day number is valid)
if (str[0].getMonth () === +str[2] - 1)
return str[0];
}
return undefined; }
但似乎无法创建嵌套对象数组(?)。我认为标记是这样的:
<ul>
<li item-checked='false' item-expanded='false'><a href='http://mtv.me'>2017</a>
<ul>
<li item-expanded='false'>MONTH
<ul>
<li item-expanded='false'>DAY
<ul>
<div id='mphoto' style='display: flex;align-items: center;'>
<li>PHOTO</li>
<img style='display:float;z-index:0.5;' id='Imagem1' onmouseover="CallModal(Imagem1);" HEIGHT=50 WIDTH=50 src="http://my.ip.address/images/20170108-152411.jpg" >
</div>
<li>PHOTO</li>
<li>PHOTO</li>
<li>PHOTO</li>
<li>PHOTO</li>
<li>PHOTO</li>
</ul>
</li>
</ul></li>
<li item-expanded='false'>MONTH
<ul>
<li item-expanded='false'>DAY
<ul>
<div id='mphoto' style='display: flex;align-items: center;'>
<li>PHOTO</li>
<img style='display:float;z-index:0.5;' id='Imagem2' onmouseover="CallModal(Imagem2);" HEIGHT=50 WIDTH=50 src="http://my.ip.address/images/20170108-180000.jpg" >
</div>
</ul>
</li>
</ul>
</li>
</ul>
</li>
干杯