gpt4 book ai didi

ruby-on-rails - Marionette CompositeView 为 Collection 中的每个模型而不是 ItemView 呈现自身(Marionette Rails)

转载 作者:行者123 更新时间:2023-12-04 02:44:35 25 4
gpt4 key购买 nike

基本上,我试图将 CompositeView 呈现为一个简单的四列列表,其中包含一个表头,其中集合中的每个模型都呈现为一个并附加到 .我正在关注 an example of Derick's非常接近,只有一点点变化,但不幸的是得到了一些非常奇怪的结果。

View 不是渲染每个 itemView,而是引用自身并为集合中的每个项目重新渲染,生成一个新的表和表头。在此之前,它自己渲染 compositeView。

我有一个 itemView,它的模板是一组项目,还有一个引用它的 compositeView,它是一个表

复合 View :

class App.module('Views.Parts').Index extends Backbone.Marionette.CompositeView
template: 'parts/index'
itemView: App.Views.Parts.Part
tagName: 'table'
itemViewContainer: 'tbody'
appendHtml: (collectionView, itemView, index)->
collectionView.$el.append(itemView.el)

项目 View :

class App.module('Views.Parts').Part extends Backbone.App.ItemView
tagName: 'tr'
template: 'parts/part'
events:
"click .destroy": "destroy"
destroy: (e) ->
e.preventDefault()
@model.destroy()
onRender: ->
@stickIt()

Controller

class App.Controllers.Parts
constructor: ->
@parts = new App.Collections.Parts
@parts.reset(App.parts)
App.parts = null

showView: (view)->
App.mainRegion.show view

index: ->
view = new App.Views.Parts.Index
collection: @parts
@showView view

我还听说在 CompositeView 之前声明 ItemView 是必要的——但是由于它是一个 Marionette Rails 项目, View 实际上位于不同的目录中。我是否必须声明它们的顺序或以另一种方式将它们相应地相互绑定(bind)?

最佳答案

您不希望有 itemViewContainerappendHtml。尝试删除后者,您的 View 应该可以正确呈现。

关于ruby-on-rails - Marionette CompositeView 为 Collection 中的每个模型而不是 ItemView 呈现自身(Marionette Rails),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19127436/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com