0

わかりましたので、ポッドキャストの JSON フィードを返す API があります。

これらのポッドキャストはフロントエンドに表示されますが、順序は私が必要としている順序とは正反対です。呼び出している JSON フィードが正しい順序になっているため、さらに混乱していますが、フロントエンドでそのように機能させることはできません。私が取り組んでいるコードを見てください:

http://pastebin.com/bSamtFUw

var cache = new CacheProvider;


var Photo = Backbone.Model.extend({
   subalbum: function() { return 'c' + gallery._currentsub; }
});



var PhotoCollection = Backbone.Collection.extend({
    model: Photo,
    comparator: function(item) {
        return item.get('pid');
    }
});

function removeFallbacks(){
  var query = $('.jstest,.gallery');
        if(query.length){
          query.remove();
        }
}


var IndexView = Backbone.View.extend({
    el: $('#main'),
    indexTemplate: $("#indexTmpl").template(),

    render: function() {
        removeFallbacks();
        var sg = this;

        this.el.fadeOut('fast', function() {
        sg.el.empty();
        $.tmpl(sg.indexTemplate, sg.model.toArray()).appendTo(sg.el);
        sg.el.fadeIn('fast');
        });
        return this;
    }

});


var SubalbumView = Backbone.View.extend({
    el: $('#main'),
    indexTemplate: $("#subindexTmpl").template(),

    initialize: function(options){

    },

    render: function() {
        var sg = this;
        removeFallbacks();
        this.el.fadeOut('fast', function() {
            sg.el.empty();
            $.tmpl(sg.indexTemplate, sg.model.toArray()).appendTo(sg.el);
            sg.el.fadeIn('fast');
        });
        return this;
    }

});


var PhotoView = Backbone.View.extend({
    el: $('#main'),
    itemTemplate: $("#itemTmpl").template(),


    initialize: function(options) {
        this.album = options.album;

    },

    render: function() {
        var sg = this;
        removeFallbacks();     
        this.el.fadeOut('fast', function() {
            sg.el.empty();
            $.tmpl(sg.itemTemplate, sg.model).appendTo(sg.el);
            sg.el.fadeIn('fast');
        });
        return this;
    }
});




var Gallery = Backbone.Controller.extend({
    _index: null,
    _photos: null,
    _album :null,
    _subalbums:null,
    _subphotos:null,
    _data:null,
    _photosview:null,
    _currentsub:null,

    routes: {
        "": "index",
        "subalbum/:id": "hashsub",
        "subalbum/:id/" : "directphoto",
        "subalbum/:id/:num" : "hashphoto"
    },

    initialize: function(options) {

        var ws = this;

        if (this._index === null){
            $.ajax({
                url: 'http://mikegradio.com/api/v1/podcasts/export/?tags__title=sports&sort_by=-rank&limit=50',
                dataType: 'json',
                data: {},
                success: function(data) {
                    ws._data = data;
                    ws._photos = new PhotoCollection(data);
                    ws._index = new IndexView({model: ws._photos}); 
                    Backbone.history.loadUrl();

                }
            });
            return this;
        }
        return this;
    },


    index: function() {
        this._index.render();
    },


    hashsub:function(id){

       var properindex = id.replace('c','');    
       this._currentsub = properindex;
       this._subphotos = cache.get('pc' + properindex) || cache.set('pc' + properindex, new PhotoCollection(this._data[properindex].subalbum));
       this._subalbums = cache.get('sv' + properindex) || cache.set('sv' + properindex, new SubalbumView({model: this._subphotos}));
       this._subalbums.render();


    },

    directphoto: function(id){

    },

      hashphoto: function(num, id){
        this._currentsub = num;

        num = num.replace('c','');

        if(this._subphotos == undefined){
           this._subphotos = cache.get('pc' + num) || cache.set('pc' + num, new PhotoCollection(this._data[num].subalbum));
         }  
        this._subphotos.at(id)._view = new PhotoView({model: this._subphotos.at(id)});
        this._subphotos.at(id)._view.render();

      }
});


gallery = new Gallery();
Backbone.history.start();

http://pastebin.com/VZ6aTj9T#

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

        <link rel="stylesheet" href="gallery.css" type="text/css" media="screen" charset="utf-8" />
        <link rel="stylesheet" href="shadows.css" type="text/css" media="screen" charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <link rel="stylesheet" href="buttons.css" type="text/css" media="screen" charset="utf-8" />
        <link rel="stylesheet" href="ipad.css" type="text/css" media="screen" charset="utf-8" />
        <link rel="stylesheet" href="desktop.css" type="text/css" media="screen" charset="utf-8" />

                <script id="indexTmpl" type="text/x-jquery-tmpl">
                <div class="item drop-shadow round">
                 <div class="item-image">
                     <a href="#subalbum/${cid}"><img src="${attributes.image}" alt="${attributes.title}" />
                     </a>
                 </div>

                </div>
                </script>


                <script id="subindexTmpl" type="text/x-jquery-tmpl">
                <div class="track drop-shadow round">
                 <div class="item-image subalbum">
                      <div class="item-artist">${attributes.title}</div>
                   <audio controls preload="none" id="audioControl" id="audio-player" src="${attributes.media}" type="audio/mp3" controls="controls"></audio>
                      <div class="item-price">${attributes.duration}</div>
                      <a href="#subalbum/${subalbum}/${attributes.cid}">Shop</a>
                </div>

                 </div>
                </script>

                    <script id="itemTmpl" type="text/x-jquery-tmpl">
                <div class="item-detail">
                  <div class="item-image drop-shadow round"><img src="${attributes.large_image}" alt="${attributes.title}" /></div>
                  <div class="item-info">
                    <div class="item-artist">${attributes.artist}</div>
                    <div class="item-title">${attributes.title}</div>
                    <div class="item-price">$${attributes.price}</div>
                    <br />
                    <div class="item-link"><a href="${attributes.url}" class="button">Buy this item</a></div>
                    <div class="back-link"><a href="#" class="button">&laquo; Back to Albums</a></div>
                  </div>
                </div>
                </script>

    </head>
    <body>
        <div id="container">
            <div id="main">
            </div>
        </div>
        <script src="LAB.min.js" type="text/javascript"></script>


<script type="text/javascript">
           $LAB
           .script("jquery-1.4.4.min.js").wait()
           .script("jquery.tmpl.min.js")
           .script("underscore-min.js")
           .script("backbone-min.js")
           .script("cacheprovider.js").wait()
           .script("gallery.js");      
        </script>
    </body>
</html>

http://mikegradio.com/api/v1/podcasts/export/?tags__title=sports&sort_by=-rank&limit=50

どんな助けでも大歓迎です!

4

1 に答える 1

1

コレクションを逆順に並べ替えようとしましたか: (コレクションを逆に戻すための否定に注意してください。)

comparator: function(item) {
    return -item.get('pid');
}
于 2014-05-28T01:58:09.283 に答える