backbone-views

Need help understanding the basics of nested views in backbone

天涯浪子 提交于 2019-12-04 11:39:10
问题 I've been doing a bunch of reading about nested views in backbone.js and I understand a good amount of it, but one thing that is still puzzling me is this... If my application has a shell view that contains sub-views like page navigation, a footer, etc. that don't change in the course of using the application, do I need to render the shell for every route or do I do some kind of checking in the view to see if it already exists? It would seem so to me if someone didn't hit the "home" route

how and where to initialize jquery datatable in backbone view

霸气de小男生 提交于 2019-12-04 11:27:29
My html template look like this: <script type="text/template" id="players-template"> <table id="example" class="table table-striped table-bordered table-condensed table-hover"> <thead> <tr> <th>Name</th> <th>group</th> <th></th> </tr> </thead> <tbody id="playersTable"></tbody> </table> </script> <script type="text/template" id="player-list-item-template"> <td><@= name @></td> <td> <@ _.each(hroups, function(group) { @> <@= group.role @> <@ }); @> </td> </script> My backbone view is as follows: playerView = Backbone.View.extend({ template: _.template( $("#player-template").html() ), initialize:

Backbone Marionette, Composite View initializes twice

时间秒杀一切 提交于 2019-12-04 11:18:32
问题 I'm using a composite view that has $.dialog called on it's $el. The composite view is then listing items from a collection. Now i've tried multiple ways to render the collection items: fetching from outside the composite view before and after attaching it to the view, fetching inside the view, preloading the collection from my server script, etc... all seem to work but the same problem occurs.. as soon as the composite view see's this collection, it calls it's own initialize function again..

Marionette bubble event from itemview to parent layoutview?

吃可爱长大的小学妹 提交于 2019-12-04 10:38:20
问题 I have a layout view with a region, in that region I have a item view that triggers an event but it doesn't seem to be bubbled up to the layout view. Am I doing something wrong or is this designed behavior? I assume the itemview prefix is not added as the parent view is not a collection view? Either way the event is never bubbled to the layout view. layoutView = Marionette.Layout.extend({ template: "#layout-template", regions: { titleRegion: "#job-title-region" }, triggers: { "save:clicked" :

MarionetteJS: Application Regions vs. Layouts [duplicate]

风格不统一 提交于 2019-12-04 09:48:03
问题 This question already has an answer here : What to use since Marionette Application Regions are deprecated (1 answer) Closed 3 years ago . I was reading the documentation of the latest version (2.3.0) and it is saying that Application Regions are now deprecated. Application Regions Warning: deprecated This feature is deprecated. Instead of using the Application as the root of your view tree, you should use a Layout View. To scope your Layout View to the entire document, you could set its el

How to check if sidebar view has already been rendered in backbone?

半城伤御伤魂 提交于 2019-12-04 06:25:52
问题 Generally, the user enters the website through the home page and then I render the sidebar view there. Next, the user clicks a link and the router renders another view and replaces the original content view. The sidebar view is not re-rendered. When the user clicks refresh while on a sub-page, the sidebar is not rendered. How do I check whether a view exists and has been rendered? 回答1: Split the responsibilities and stick to it. Don't put the sidebar rendering into the hands of the home page

Understanding Backbone and Marionette View lifecycle

烂漫一生 提交于 2019-12-04 03:28:43
I'm new to this world and I need to understand some of the concepts of Backbone and Marionette. Here I'm trying to explain some of the concepts I'm learning. It would be great to having some feedback on them. The render function defines the logic for rendering a template. When it is finished, the onRender callback is called. Here I suppose the rendered view has been not attached to the DOM. It is composed by a tagName (the default is div ) that contains the template I attached to it. To explicitly insert that tag into the DOM I need to append it somewhere. Am I wrong? In general, I do the

How to attach Backbone.Marionette view to existing element without creating extra element

我只是一个虾纸丫 提交于 2019-12-03 16:14:23
Say I have these two Backbone.Marionette views: var FooView = Backbone.Marionette.ItemView.extend({ tagName: p, id: 'foo', template: this.templates.summary }); var BarView = Backbone.Marionette.ItemView.extend({ template: this.templates.summary }); And then I want to show them inside an app region, like so: App.contentRegion.show(new FooView/BarView()); The first view would create a new element and append it to the region. I thought the second way would be more like a standard Backbone view and attach itself to the region without creating a new element, but it wraps it in a tag. Is there a way

Binding multiple event types in backbone views

≡放荡痞女 提交于 2019-12-03 14:39:04
问题 I was wondering if it is possible to bind multiple event types in backbone within a single line. Consider the following: var MyView = Backbone.View.extend({ id: 'foo', events: { 'click .bar': 'doSomething', 'touchstart .bar': 'doSomething' }, doSomething: function(e) { console.log(e.type); } }); Basically what I am wondering is if it is possible to combine the event binding for 'click' and 'touchstart' into one line - along the lines of: events: { 'click,touchstart .bar': 'doSomething' } Any

Backbone.js view instance variables?

拟墨画扇 提交于 2019-12-03 10:53:31
I'm learning Backbone.js and am trying to figure out whether it's possible to have instance variables in Backbone views. My goal is to load a view's templates from an external file when a view is being instantiated. Currently I'm storing them in a global variable in the Backbone app's global namespace, but it would be cleaner to store the templates in a view's instance variables. Currently I have it set up like this: var templates = {}; MessageView = Backbone.View.extend({ initialize: function() { $.get('js/Test2Templates.tpl', function(doc) { var tmpls = $(doc).filter('template'); templates[