- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在使用项目/复合 View 访问模型属性时遇到了一些问题。在我的 ItemView 中,我拥有所有模型属性数据,但是当我想要输出 <%=username%>
时在我的 html/模板中什么也没有。
我不知道为什么这不起作用。通常代码和我的一样简单。
要点:https://gist.github.com/e6e68b525468606bd039或如下:
index.html:
<section>
<%= test %>
<ul class="thumbnails" id='userslist'></ul>
</section>
<script type="text/template" id="usertemplate">
Username: <%= username %>
</script>
测试.咖啡:
define [ 'jquery', 'underscore', 'backbone', 'marionette', 'text!templates/us/index.html' ], ( $, _, Backbone, Marionette, TPL) ->
class UserView extends Backbone.Marionette.ItemView
template : '#usertemplate'
tagName : 'li'
className : 'span2'
initialize: ->
console.log 'm:', @model.attributes
class UsPageView extends Backbone.Marionette.CompositeView
template : _.template TPL
itemView : UserView
itemViewContainer: "#userslist"
initialize: (options) ->
@collection = options.collection
@collection.fetch()
appendHtml: (cView, iView, idx) ->
cView.$(@itemViewContainer).append iView.el
serializeData: ->
test: 'ok'
UsPageView
console.log 打印:Object { username: "Foo" }
最佳答案
我找到了一个临时解决方案:- 我使用模板代码创建一个新文件:
// --- members.html
Username: <%= username %>
我像这样更改了我的 ItemView 类:
define [ 'jquery', 'underscore', 'backbone', 'marionette', 'text!templates/us/index.html', 'text!templates/us/members.html' ], ( $, _, Backbone, Marionette, TPL, M) ->
class UserView extends Backbone.Marionette.ItemView
tagName : 'li'
className : 'span2'
template: (serializedModel) =>
_.template M, @model.toJSON()
class UsPageView extends Backbone.Marionette.CompositeView
template : _.template TPL
itemView : UserView
itemViewContainer : "#userslist"
initialize: (options) ->
@collection = options.collection
@collection.fetch()
appendHtml: (cView, iView, idx) ->
cView.$(@itemViewContainer).append iView.el
UsPageView
这个解决方案对我有用。对于我最初的问题,似乎是当我想要恢复我的模板原始文本时。通常 $('#usertemplate').text() 返回带有所有 '<%= ... %>' 的模板数据,但没有。我不知道为什么。
如果有人找到解决方案,我仍然感兴趣:)
关于javascript - 无法使用 Backbone.Marionette 访问模型属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14566944/
我真的不明白它们是如何有用的。原文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
我是一名优秀的程序员,十分优秀!