- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正尝试在 CoffeeScript 中创建此示例的基本版本:http://davidsulc.com/blog/2012/04/15/a-simple-backbone-marionette-tutorial/ .所有依赖项都按照我编写它们的顺序(在正文中)声明为 .coffee 文件,jQuery + Underscore + Backbone + Marionette 在头部。
我有一个模型,thing.coffee
$ ->
console.log 'load model'
class Thing extends Backbone.Model
defaults:
myValue: null
initialize: ->
console.log 'new thing'
window.Thing = Thing
我的第一个小问题是作用域:如果我不声明 window.Thing
,下一个文件(Things
的集合)找不到模型 Thing
等等。我在那里做错了什么?
我有一个收藏,things.coffee
$ ->
console.log 'load collection'
class Things extends Backbone.Collection
model: Thing
window.Things = Things
我有 Marionette View ,thing_view.coffee
$ ->
console.log 'load composite model view'
ThingView = Backbone.Marionette.ItemView.extend(
template: '#template-thing'
tagName: 'tr'
)
window.ThingView = ThingView
我有 Marionette View ,things_view.coffee
$ ->
console.log 'load composite collection view'
ThingsView = Backbone.Marionette.CompositeView.extend(
tagName: 'table'
id: 'things'
template: '#template-things'
itemView: ThingView
appendHtml: (collectionView, itemView) ->
collectionView.$('tbody').append itemView.el
)
window.ThingsView = ThingsView
我有一个应用myapp.coffee
$ ->
console.log 'load app'
# Load default data
thingsCollection = new Things([
new Thing(myValue: 'uno'),
new Thing(myValue: 'dos')
])
data:
thingsCollection: thingsCollection
# Create application, specify default layouts
MyApp = new Backbone.Marionette.Application()
MyApp.addRegions singleRegion: '#content'
# On application init...
MyApp.addInitializer (data) ->
console.log 'Init application...'
thingsView = new ThingsView(collection: data.thingsCollection)
MyApp.singleRegion.show data.thingsView
# Start application
MyApp.start data
我的 html 文件如下所示:
<div id="content">
<script type="text/template" id="template-things">
<thead>
<tr class='header'>
<th>myValue</th>
</tr>
</thead>
<tbody>
</tbody>
</script>
<script type="text/template" id="template-thing">
<td><%= myValue %></td>
</script>
</div>
在 console.log
之后:
load model
load collection
load composite model view
composite collection view
load app
Init application...
Uncaught TypeError: Cannot call method 'render' of undefined
所以,不用说我对发生的事情感到困惑 - 我敢肯定这里有很多问题,所以请帮忙!
最佳答案
window.Thing
是 Coffeescript 的全局命名空间污染避免的副产品。解决这个问题的惯用方法是 use an App
namespace .
仅在 DOM 加载时初始化您的类是一个 Backbone anti-pattern .如果您为您的类命名,那么您只需确保以正确的顺序加载它们(项目 View 在 Collection View 之前)并且它们可以立即创建,而不是在页面加载后创建。
您能告诉我们 Uncaught TypeError
发生在哪里吗?
关于javascript - CoffeeScript/Backbone/Marionette - 教程示例转换和范围界定问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10525379/
我真的不明白它们是如何有用的。原文article引入了初始化程序,这是代码示例: App = new Backbone.Marionette.Application(); App.addInitial
我正在准备使用 Backbone Marionette 迁移我的应用程序,但路由中出现错误: window.App = new Backbone.Marionette.Application
我正在尝试将 marionette.js 用于我的 Backbone 应用程序,但我对如何组织布局/区域并呈现它们感到有些困惑。 我正在寻找具有嵌套布局和区域的示例应用程序,以便我能更好地理解它。有什
我有一个带有区域的布局。当 Layout 初始化时,我希望它自动初始化一个预设 View 以进入它的区域,并在 Layout 本身显示/关闭时显示/关闭它。 当前示例来自 https://github
//当我点击 kickassessor 按钮时,它会更新数据库,但 View 不会更新。这是我的代码。 返回 Marionette.ItemView.extend( { initialize
我有需要显示/编辑的数据,这些数据似乎与 Marionette 提供的内置 View 不自然。让我举个例子来说明。 假设我想列出/编辑书籍。每本书都有一个 ISBN、一个书名和 0 个或多个标签。基本
我一直在查看各种 Marionette 问题,但没有找到我想要的,希望有人能给我一些合理的建议和一些建议。我是新手,只是想在我在 github 上选择的样板启动包上构建 https://github.
随着我的应用程序的增长,我觉得需要更结构化的路由器/ Controller 设置。 Marionette 文档提到以下内容: It is recommended that you divide you
在我的应用程序中,我添加了 Marionette.sync 插件并覆盖这些方法: Backbone.Marionette.TemplateCache.prototype.loadTemplate =
我想知道是否有可能以某种方式扩展 Marionette Layout 机制基于创建一种类似导航的堆栈。 Marionette 行为。 在区域 show() 的 View 之前,它会在当前显示的 Vie
看起来 Backbone.Marionette View 为事件等操作 DOM,所以我猜这不像更改基类引用那样微不足道,例如Backbone.View 到 BaseView。 有没有人解决过这个问题?
我正在使用 Marionette Layout .show渲染 CollectionView并想知道是否有办法检测 全部 ItemView children 已经完成了渲染? 我的代码的简化版本是:
因此,我不确定我是否完全理解应该如何触发此回调。如果您采用准系统模型、集合和 View : PatchModel = Backbone.Model.extend({}); PatchCollectio
我正在查看 Backbone Marionette,它似乎对我当前的项目很有前途。但是,无论 startWithParent 设置如何,添加模块时它们似乎都会自动启动。这是我遇到问题的一段代码(其中一
我是 Marionette 的新手,无法理解事件... 我有一个触发事件的 ItemView,我想在应用程序级别接收此事件,但是当我的应用程序监听此事件时,没有任何 react ... 如果事件聚合器
我有一个 CollectionView class MyCollectionView extends Backbone.Marionette.CollectionView itemView: My
我有一个复合 View ,在将模型添加到 View 集合时抛出以下错误:Uncaught ItemViewContainerMissingError: Missing itemViewContaine
我已经建立了一个项目,在其中扩展了包含两个不同区域的 Backbone.Marionette.Layout。该布局可以用作整个应用程序的组件。特别是,区域设置如下。 regions : { m
基本上,我试图将 CompositeView 呈现为一个简单的四列列表,其中包含一个表头,其中集合中的每个模型都呈现为一个并附加到 .我正在关注 an example of Derick's非常接近,
我正在尝试包含应用程序实例以使用其事件聚合器,如图所示 here 当我将实例包含在 View 中时,出现错误。 在 Requirejs 配置文件中启动 App.Bootloader.js: requi
我是一名优秀的程序员,十分优秀!