2013-09-26 44 views
0

我试图在现有的代码话语烬Rails应用程序添加一个监视列表功能添加新的功能,话语

我已经addded下面的代码

Discourse.Route.buildRoutes(function() { 
    var router = this; 

    this.resource('watchLists', { path: '/watch_lists' }, function() { 
     this.resource('watchList', {path: ':watch_list_id'}); 
    }); 
    }); 

在余烬控制器

Discourse.WatchListsController = Discourse.ObjectController.extend({}); 

在余烬模型中

Discourse.WatchList = Discourse.Model.extend({}); 

    Discourse.WatchList.reopenClass({ 
     find: function() { 
      jQuery.getJSON("watch_lists").then(function(json) { 
      var watch_lists = json.watch_lists.map(function(attrs) { 
      return Discourse.WatchList.create(attrs); 
     }); 
    }); 

在余烬视图JS

Discourse.WatchListsView = Ember.View.extend({}); 

在余烬路线JS

 Discourse.WatchListsRoute = Discourse.Route.extend({ 
     model: function() { 
      return Discourse.WatchList.find(); 
     } 
    }); 

当我renderring车把模板我正在一个WatchListsController对象withot我们从阿贾克斯获得了数据。

任何机构都可以指出我在哪里做错了。

回答

2

我看到两个可能的问题。

首先,您可能想要WatchListsController扩展Discourse.ArrayController而不是Discourse.ObjectController

其次您的reopen块在您发布的示例代码中无效。我算了四个{但只有两个}。你可能想要的东西是这样的:

Discourse.WatchList.reopenClass({ 
    find: function() { 
    return jQuery.getJSON("watch_lists").then(function(json) { 
     return json.watch_lists.map(function(attrs) { 
     return Discourse.WatchList.create(attrs); 
     } 
    }); 
    } 
});