Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Backbone.js 如何使用Eco显示主干嵌套属性?_Backbone.js_Eco - Fatal编程技术网

Backbone.js 如何使用Eco显示主干嵌套属性?

Backbone.js 如何使用Eco显示主干嵌套属性?,backbone.js,eco,Backbone.js,Eco,我遵循了Ryan Bates在Backbone.js上的示例,使用Backbone+Eco启动了一个项目。太棒了。但是,我一直在尝试显示嵌套属性。 例如,我正在尝试这样做:在index.jst.eco中 我得到了未捕获的TypeError:无法调用未定义的方法'get' 不过,我可以去上班 以下是REST API数据: [ : { : : "id":"5004095283de4ca9ff000005", : : "created_at":"2012-07-16T12:30:1

我遵循了Ryan Bates在Backbone.js上的示例,使用Backbone+Eco启动了一个项目。太棒了。但是,我一直在尝试显示嵌套属性。 例如,我正在尝试这样做:在index.jst.eco中 我得到了未捕获的TypeError:无法调用未定义的方法'get' 不过,我可以去上班

以下是REST API数据:

[
:   {
:   :   "id":"5004095283de4ca9ff000005",
:   :   "created_at":"2012-07-16T12:30:10Z",
:   :   "stream_type":"project",
:   :   "user":
:   :   {
:   :   :   "id":"5002f30560de7d0ffb000003",
:   :   :   "name":"Regular User2"
:   :   },
...
我也尝试过使用Backbone.DeepModel扩展我的模型,但这似乎不起作用

class Project1.Collections.Streams extends Backbone.Collection
  url: '/streams'
  model: Topaz.Models.Stream

class Project1.Models.Stream extends Backbone.DeepModel
以下是我对该系列的看法,相当标准

class Project1.Views.StreamsIndex extends Backbone.View
  #views/streams/index.js
  template: JST['streams/index']

  initialize: ->
    @collection.on('reset', @render, this)
    @collection.on('add', @appendStream, this)  #rerenders entire template

  render: ->
    $(@el).html(@template())
    @collection.each(@appendStream)
    this

  appendStream: (stream) =>
    view = new Topaz.Views.Stream(model: stream)
    @$('#streams').append(view.render().el) # looks for the #entries element within the view’s element and not on the page directly
这是模型的视图

class Project1.Views.Stream extends Backbone.View

  template: JST['streams/show']
  className: 'stream-item'

  initialize: ->
    @model.on('change', @render, this)   #The change event is triggered by Backbone when a model saves

  render: ->
    $(@el).html(@template(stream: @model))
    this