使用轮播以给定格式创建ajava脚本数组?

时间:2012-11-05 12:48:42

标签: javascript

使用carousel创建给定格式的ajava脚本数组?

我使用carousel.js& carousel.css,它的工作正常与静态数据,但当我试图把动态数据发生热的时候。我无法以给定的格式创建值数组。

   <script>
                  var carousel2 = new widgets.Carousel( {

                        uuid : "carousel2",
                        widgetDir : "carousel/",
                        args : { "theme" : "gray", "scrollCarousel" : true, },
                        value : [


                           { 
                             "image" : "images/banner/big_banner_01.jpg",

                           },

                           { 
                             "image" : "images/banner/big_banner_02.jpg",

                           },

                           {
                             "image" : "images/banner/big_banner_03.jpg",

                             },

                           { 
                              "image" : "images/banner/big_banner_04.jpg",

                           },

                           { 
                              "image" : "images/banner/big_banner_05.jpg",

                           }
                        ]
                      } );
                </script>


      I need to pass the value for "value" key dynamically.  How can i form this dynamically .IM TRYING WITH THE BELOW ONE

        <repeat index="index.value" ref="DATA">
        <repeat ref="VAL">
            <choose ref="LANGUAGE">
                <when value="${lang}">hiii
                    <script>
                    val[index.value] = "{"+"'image' :" +${IMAGE}+"}";</script>
                </when>
                <otherwise/>
            </choose>
        </repeat>
    </repeat>


    This is not working.

1 个答案:

答案 0 :(得分:0)

<script>
  var generateCaroseul = {

            getData: function(){

                //loop through html to create an object with the data.
                var dataObj = null;
                $('li').each(function(index) {
                    var imgUrl = $(this).attr("src");
                    dataObj.add("image", imgUrl);
                });

                return dataObj;
            }
  };


  var carousel2 = new widgets.Carousel( {

        uuid : "carousel2",
        widgetDir : "carousel/",
        args : { "theme" : "gray", "scrollCarousel" : true, },
        value : generateCaroseul.getData()
      } );
</script>

<script> var generateCaroseul = { getData: function(){ //loop through html to create an object with the data. var dataObj = null; $('li').each(function(index) { var imgUrl = $(this).attr("src"); dataObj.add("image", imgUrl); }); return dataObj; } }; var carousel2 = new widgets.Carousel( { uuid : "carousel2", widgetDir : "carousel/", args : { "theme" : "gray", "scrollCarousel" : true, }, value : generateCaroseul.getData() } ); </script>