如何向 backgridjs 元素添加导航



我对主干网和后网格很陌生,想知道如何添加用于导航到后网格的锚点?到目前为止,我创建了许多网格,并将其元信息存储在导航集合中。导航和网格元素已呈现,但我看不到如何将导航锚点连接到网格表的任何内容。

示例代码,其中我使用 grid.render((.cid,它不起作用:

  races = { };  
  docs.forEach(function(doc) {
    if (races[doc.s_y] === undefined) {
      races[doc.s_y] = {};
    }
    if (races[doc.s_y][doc.t] === undefined) {
      races[doc.s_y][doc.t] = new Races();
      races[doc.s_y][doc.t].add(doc);
    } else {
      races[doc.s_y][doc.t].add(doc);
    }
  });
  console.log("Found number of docs", docs.length);
  var NavigationCollection = Backbone.Collection.extend({
    model : Race
  });
  var navCollection = new NavigationCollection();
  var NavView = Backbone.View.extend({  
    el : $('ul'), 
    initialize: function(){
      _.bindAll(this, 'render'); 
      // this.render();  
    },  
    render : function() {
      this.collection.each(function (race) {
        this.$el.append("<li><a href=#" + race.get("link") + ">" + race.get("track") + " " + race.get("year") + "</a></li>");
      }, this);
      return this; // remember this for chaining
    }
  });
  var grids = {};
  for (var key in races) {
    if (races.hasOwnProperty(key)) {
      for (var track in races[key]) {
        var grid = new Backgrid.Grid({
          columns: columns,
          collection: races[key][track],
          emptyText: "No Data, Loading"
        });
        if (grids[key] === undefined) {
          grids[key] = {};
        }
        grids[key][track] = grid;
        console.log(key + " -> " + races[key][track]);
        grid.render().sort("p", "ascending");
        console.log(grid.render());
        navCollection.add({ year: key, track: track, link: grid.render().cid });
        $("#race-results").append(grid.render().el);
      }
    }
  }
  var navView = new NavView({
    collection: navCollection
  });
  $("#navigation").append(navView.render().el);

刚刚发现可以在网格定义中定义"id"。我在那里使用"跟踪"并将其保存为导航元素中的"链接"。也许有更好的方法来实现这一目标?

相关内容

  • 没有找到相关文章