0

この質問の仕方がまったくわかりません。誰かがこれを理解していない場合、申し訳ありません。つまり、私はオブジェクトを持っていて、それを使用してループしていeach functionます。サブオブジェクト(内部オブジェクト)を取得すると、同じものに割り当て直したいのeach functionですが、良い考えは何ですか?

私の問題を見てください:

私のオブジェクト:

var xploreMaps = {
    radious:55,
    stroke:5,strokeColor:'#fff',
    opacity:0.8,fontSize:13,line:10,
    cGtext:{
        length:5,
        lineColor:'#579549',
        prop:{
            0:{link:'catalogs .html',color:'#7a5967',text:'Catalogs',
            subLink:{0:{link:'SEO_SMM.html',color:'#4e4b69',text:'SEO/SMM',align:'top'},1:{link:'site_analytics.html',color:'#545454',text:'Site analytics',align:'btm'}}},
            1:{link:'socialmedia.html',color:'#1e9ead',text:'Innovation'},
            2:{link:'loyalty .html',color:'#8fad34',text:'Ideation'},
            3:{link:'promotions .html',color:'#563b64',text:'Promotions'},
            4:{link:'implementations.html',color:'#2c6566',text:'Implementations',
            subLink:{0:{link:'integrating.html',color:'#4c4a66',text:'Integrating',align:'top'},1:{link:'payment.html',color:'#948048',text:'Payment',align:'btm'}}}
            }
    }
}

var object = xploreMaps[id].prop || 'i need subLink';

私の機能:

    $.each(object, function (n,d) {

                var Color = this.color,link = this.link,text=this.text,**subLink** = this.subLink || '';

   // if the sublink there, i need to put back to each, and do the same stuff, what i do for it's parent object.

                var myTimeout = setTimeout(function(){
                    redSubCircles.push(paper.path("M"+x +" "+y)
                    .attr({stroke:brdColor})
                    .animate({path:"M"+(x-((stroke/2)+(n*((radious*2)+stroke+line)))) +" "+y+'l'+(-line)+' 0'},1000,
                        function(){
                            var c =    paper.circle((x-(radious+stroke+line) - n*((radious*2)+stroke+line)),y,radious)
                            .attr({
                                stroke:strokeCl,
                                'stroke-width':stroke,
                                opacity:opacity,
                                fill:Color,
                                href:link
                            });

                            var p =    paper.text((x-(radious+stroke+line) - n*((radious*2)+stroke+line)),y,text)
                            .attr({fill:strokeCl,'font-size':fSize,href:link})

                            redSubCircles.push(c,p)//push to set;-

                        }));
                },1000*n)
            } )

私が間違っている場合は、申し訳ありません。正しい方法を教えてください。

4

1 に答える 1

1

おそらく、whileループと一時配列が役に立ちます。

初期アイテムを一時配列に追加する一時配列にアイテムがあるときに関数を呼び出します

サブリンクに遭遇するたびに、それを繰り返し処理している一時配列にプッシュします。一時配列が大きくなり、実行を継続します。

アイテムを完了するたびに、それを削除します。Temporaray配列は小さくなり、最終的にはゼロになり、ループが完了します。

配列からアイテムを削除するには、while、push、spliceが必要です。

これが実際のスタンドアロンの例であり、デモがここにあります

<!DOCTYPE HTML>
<html lang="en-US">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<h1>looper</h1>
    <script type="text/javascript">
    function ObjectMaker(identifier) {
        var that = {
          subObj:null,
          name: identifier,
          getName: function() {
            return "I am "+this.name;
          },
          setSubObj: function(sub) {
            this.subObj = sub ;
          }       
        }
        return that;
    }
    var twoAndAHalf = ObjectMaker("two and  a half");
    var two = ObjectMaker("two");
    two.setSubObj(twoAndAHalf);
    var items = [ObjectMaker("one"),two,ObjectMaker("three")];
    while(items.length>0) {
        if (items[0].subObj != null) {
            items.push(items[0].subObj);
        }
        alert(items[0].getName());
        items.splice(0,1);
    }
    </script>
</body>
</html>
于 2012-11-08T12:54:58.843 に答える