0

我有一个名称:字符串和状态:整数的项目模型。有5种状态。例如,我想将所有状态为 3 的项目放入#prospects div。我怎样才能使这项工作?

appendProject: (project) =>
  # this renders all projects
  view = new Trackproject.Views.Project(model: project)
  @$('#projects').append(view.render().el)
  # this is how i want it to work
  @$('#prospects').append(state3.render().el)
  @$('#upcoming').append(state4.render().el)

我认为您可以在集合文件中对其进行过滤,但我不知道如何将其加载到视图中。

我使用 Rails、Backbone 和 Coffeescript

4

2 回答 2

0
_.each(projectCollection.where({state: 3}), function(project) {
    $('#prospects').append($('<span>' + project.get('name') + '</span>'));
});
于 2012-09-19T17:41:18.663 回答
0

正确答案是

  appendProject: (project) =>
    view = new Trackproject.Views.Project(
      model: project
    )
    state = project.get("state")
    if state is 1
      @$("#projects").append view.render().el
    else if state is 2
      @$("#prospects").append view.render().el
    else if state is 3
      @$("#upcoming").append view.render().el
    else if state is 4
      @$("#current").append view.render().el
    else if state is 5
      @$("#completed").append view.render().el
    else
      @$("#projects").append view.render().el
于 2012-09-24T15:04:29.063 回答