【问题标题】:Ember.js dynamic linksEmber.js 动态链接
【发布时间】:2014-01-06 16:42:42
【问题描述】:

我正在尝试开发一个涉及我当地跑步团体比赛结果的网络应用程序。 Ember.js 看起来是一个很好的网站开发框架。

此时此刻我的代码:

App.Router.map(function() {
   this.resource('results', function(){
       this.resource('year');
   });
});

App.ResultsRoute=Ember.Route.extend({
    model: function() {
        return $.getJSON("../api/api.php?method=years");
        //returns a JSON array with all the years a certain race went through => [{"year":"2008"},{"year":"2009"},{"year":"2010"}]
    },
});

App.YearRoute=Ember.Route.extend({
    model: function(params){
    //some horrible code
    }   
});

在我网站的左侧,所有年份都显示在列表中。 当我点击一年时,比赛结果出现在右侧。

当我点击 2008 年时,如何调整 Router.map 以使 url 看起来像“www.example.com/index.html#/results/2008”?

作为一个菜鸟程序员,我很难弄清楚这一点。

【问题讨论】:

    标签: javascript dynamic ember.js


    【解决方案1】:
    App.Router.map(function() {
      this.resource('results', function(){
        this.resource('year', {path:'/:year'});
      });
    });
    

    这是一个例子

    http://emberjs.jsbin.com/oMAYUzIq/1/edit

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-31
      相关资源
      最近更新 更多