- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个显示为 CompositeView 的工具集合。此集合中的每个呈现项都是一个 ItemView。保存这些的区域的名称称为 toolNameRegion。
我在该页面中有另一个名为 toolDetailsRegion 的区域,它应该在 toolNameRegion 中呈现单击工具的属性。
这是 View :
@Tools.module "AboutApp.Show", (Show, App, Backbone, Marionette, $, _) ->
class Show.Layout extends Backbone.Marionette.Layout
template: JST['backbone/apps/about/templates/about']
regions:
toolNameRegion: "#tool-name"
toolDetailsRegion: "#tool-details"
class Show.Tool extends Backbone.Marionette.ItemView
template: JST['backbone/apps/about/templates/_tool']
tagName: "li"
events:
"click a.tool-link" : ->
@trigger "tool-name:link:clicked", @model # How the hell do I pass this to the Show.ToolDetail class?
console.log @model # shows the model attributes that was clicked
class Show.Tools extends Backbone.Marionette.CompositeView
template: JST['backbone/apps/about/templates/tools']
itemView: Show.Tool
itemViewContainer: "ul"
triggers:
"click .tool-link" : "tool:link:clicked"
class Show.ToolDetail extends Backbone.Marionette.ItemView
template: JST['backbone/apps/about/templates/tool_details']
itemView: Show.Tool
onShow: -> console.log "onShow"
onClose: -> console.log "onClose"
这是 Controller :
@Tools "AboutApp.Show", (Show, App, Backbone, Marionette, $, _) ->
Show.Controller =
showAbout: ->
tools = App.request "get:tools"
@aboutLayout = @getAboutLayout()
@aboutLayout.on "show", =>
@showTools tools
@showInitialTool tools
App.mainRegion.show @aboutLayout
showTools: (tools) ->
toolsView = @getToolsView tools
console.log toolsView
toolsView.on "tool:link:clicked", (tool) =>
console.log "model: #{tool}"
tool = @getInitialToolView tool
@aboutLayout.toolDetailsRegion.show tool
@aboutLayout.toolNameRegion.show toolsView
getToolsView: (tools) ->
new Show.Tools
collection: tools
showInitialTool: (tools) ->
initial_tool = tools.at(1)
toolView = @getInitialToolView initial_tool
@aboutLayout.toolDetailsRegion.show toolView
getToolDetailsView: ->
App.request "tool:detail:view"
toolDetailsRegion: ->
toolDetailView = @getInitialToolView
@about.toolDetailsRegion.show toolDetailView
getInitialToolView: (tool) ->
new Show.ToolDetail
model: tool
getAboutLayout: ->
new Show.Layout
如何将@model(被点击的模型)传递给 Controller ,以便@model 可以传递给 View 类 Show.ToolDetail,以便可以动态更新 toolDetailsRegion?
这是我的实体(资源):
@Tools.module "Entities", (Entities, App, Backbone, Marionette, $, _) ->
class Entities.Tool extends Backbone.Model
class Entities.ToolCollection extends Backbone.Collection
model: Entities.Tool
url: -> Routes.tools_path()
API =
setTools: (tools) ->
new Entities.ToolCollection (tools)
getToolEntities: ->
tools = new Entities.ToolCollection()
tools.fetch
reset: true
tools
App.reqres.setHandler "set:tools", (tools) ->
API.setTools tools
App.reqres.setHandler "tool:entities", ->
API.getToolEntities()
感谢@David Sulc 的回复。它仍然没有通过模型。也许我没有正确格式化它?
我从 View 中抓取模型的方式:
class Show.Tool extends Backbone.Marionette.ItemView
template: JST['backbone/apps/about/templates/_tool']
tagName: "li"
events:
"click a.tool-link" : ->
App.request "get:new:tool", @model
console.log @model
在 Controller 中:
showTools: (tools) ->
toolsView = @getToolsView tools
console.log toolsView
toolsView.on "tool:link:clicked", (tool) =>
console.log "model retrieved from click: #{tool}" # comes up undefined; how to obtain?
tool = App.request "get:new:tool" # could this be the path, but since tool is undefined, won't work?
new_tool = @getInitialToolView tool
@aboutLayout.toolDetailsRegion.show new_tool
@aboutLayout.toolNameRegion.show toolsView
感谢@David Sulc 为我指路!
在 Controller 中:
showTools: (tools) ->
toolsView = @getToolsView tools
console.log toolsView
Tools.AboutApp.Show.on "tool-name:link:clicked", (tool) =>
console.log tool.get('name')
new_tool = @getInitialToolView tool
@aboutLayout.toolDetailsRegion.show new_tool
在 View 代码中:
class Show.Tool extends Backbone.Marionette.ItemView
template: JST['backbone/apps/about/templates/_tool']
tagName: "li"
events:
"click a.tool-link" : ->
Tools.AboutApp.Show.trigger "tool-name:link:clicked", @model
console.log @model
class Show.ToolDetail extends Backbone.Marionette.ItemView
template: JST['backbone/apps/about/templates/tool_details']
itemView: Show.Tool
Tools.AboutApp.Show.on "tool-name:link:clicked", (tool) =>
console.log tool
onShow: -> console.log "onShow"
onClose: -> console.log "onClose"
最佳答案
您可以使用事件,范围限定为您当前的模块。在您的 View 中触发事件
Tools.AboutApp.Show.trigger "my:event", @model
然后,在您的 Controller 中,您可以监听该事件并更新您的其他 View :
Tools.AboutApp.Show.on "my:event", (model) ->
console.log model
您在 Show.Tools View 中使用的语法将限制在项目 View (以及在一定程度上它的 Collection View )的范围内。由于需要在不同 View 之间传递数据,我们需要扩大范围,因此使用上面的调用:在Tools.AboutApp.Show
范围内触发和监听事件。
在你看来:
events:
"click a.tool-link" : ->
Tools.AboutApp.Show.trigger "tool-name:link:clicked", @model
在您的详细 View 中:
Tools.AboutApp.Show.on "tool-name:link:clicked", (tool) =>
console.log "model retrieved from click: #{tool}"
注意我们需要使用相同的作用域和相同的触发器名称。
关于backbone.js - 如何将在 ItemView 中单击的模型发送到同一页面上的另一个 ItemView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16470569/
我有一个显示为 CompositeView 的工具集合。此集合中的每个呈现项都是一个 ItemView。保存这些的区域的名称称为 toolNameRegion。 我在该页面中有另一个名为 toolDe
我有一个 RecyclerView,我在其 View 持有者构造函数中添加了一个 onGlobalLayoutListener,如下所示 public CustomViewHolder(final V
我的结构非常简单 ProductsList.TileListView = Marionette.CollectionView.extend({ tagName: 'section',
我有一个用于表的 CompositeView。我在子 ItemView 中为每一行设置了触发器... var TableRow = Marionette.ItemView.extend({ t
我有这个代码 http://jsfiddle.net/QRcF5/2/ $(function() { var Header = Backbone.Marionette.ItemView.ext
我正在使用 Backbone、Marionette 和 RequireJS 制作应用程序,但我在使用 Marionette 的 ItemView 时遇到了问题。我正在尝试渲染模板,但总是会抛出错误。
我对主干js不太陌生,但是我想将一些参数传递给itemview的“事件”部分中的事件回调。我知道回调可以像{“事件选择器”:“回调”}一样添加。但需要将参数传递给函数“回调”。我想在回调中执行 ite
我很难解释我在寻找什么,所以我将从代码开始。 我有这样的 Marionette View : Marionette.ItemView.extend({ model: new Models.Ca
我的 View 结构从布局移动到 ItemView,如下所示 Layout -> CollectionView -> ItemView。在我的布局 View 中,我根据某些条件添加了 onShow 区
我正在使用 Marionette/Backbone 开发一个应用程序。该应用程序需要通过 AJAX 调用上传文件(使其正常工作)。我想向用户提供反馈,告知他们何时能够选择上传的文件并继续修改它。当我有
我正在尝试从 RecyclerView 中检索所有复选框以取消选中它们。但是,显示了此错误。下面是LogCat指向的类。 java.lang.IllegalArgumentException: ite
这是我的 ItemView 的代码片段: class List.GridRow extends Backbone.Marionette.ItemView tagName: 'tr' trigg
我第一次玩 Marionette 。重新呈现 ItemView 后,它们的事件未触发。简单示例: App = new Marionette.Application; App.addRegions({
我正在尝试使用 onClose 事件在删除 View 之前清理它;尽管由于某种原因它永远不会被调用。我尝试过调用region.empty、region.reset,在该区域中显示一个新 View ,甚
我想从 Marionette.ItemView 访问 app.vent。 也许可以选择将参数 (app.vent) 从 Marionette.CompositeView 传递到 Marionette.
我正在尝试延迟加载 Marionette ItemView 的模板,但事情没有按我预期的方式工作。根据有关如何重写 getTemplate 方法的一些提示,我执行了以下操作: getTemplate:
我试图在 Marionette itemview (List.SendQuestion) 中触发一个事件,但是,我无法在 Controller 中注册触发器(如下所示) 本质上,在单击“a.send”
我目前有一个复合 View ,我希望每个 ItemView 都根据其索引进行呈现。 例如,我想向每三个 ItemView 添加一个类。 我倾向于的解决方案是更改 appendHtml() 以每三次向
我有一个 ItemView,我在其中使用了 clearSearch() 函数。我需要在另一个 ItemView 中调用相同的函数,所以为了让它保持干爽,我尝试调用 clearSearch(),但没有成
我正在尝试创建一个 RecyclerView,它带有垂直列表,可以捕捉到第一个项目。为了解决这个问题,我将以下 SnapHelper 类添加到 RecyclerView 中。 public class
我是一名优秀的程序员,十分优秀!