backbone-views

Preventing backbone zombie views

时光毁灭记忆、已成空白 提交于 2019-12-23 10:16:53
问题 Note: we are using backbone 1.0.0 I am relatively new to Backbone, and was going to through some of the code a ex co-worker wrote. Rather than copy pasting stuff blindly, I wanted to understand how he did things, and that's when I started wondering about the best way to handle zombie views. var view = new editItemView({ model: this.model }); this.ui.editItemPopup.html(view.render().el).modal({ modalOverflow: true }); This creates an instance of view and pops it up in a boostrap modal. The

Backbone.js: Routing for nested views

一世执手 提交于 2019-12-23 09:26:21
问题 I'm trying to figure out following scenario: Lets say that I have two views: one for viewing items and one for buying them. The catch is that buying view is a sub view for viewing. For routing I have: var MyRouter = Backbone.Router.extend({ routes: { 'item/:id': 'viewRoute', 'item/:id/buy': 'buyRoute' } }); var router = new MyRouter; router.on("route:viewRoute", function() { // initialize main view App.mainview = new ViewItemView(); }); router.on("route:buyRoute", function() { // initialize

Different styling on the third record in Backbone + Marionette + Rails

浪子不回头ぞ 提交于 2019-12-23 03:58:14
问题 I've decided to step into the Backbone arena & after searching through BB's & Marionette's doc, I'm having a little trouble with something seemingly simple. I'm simply trying to customize what's being display on the third record. Here's how I would do it just using Rails <% @posts.each_with_index do |post, i| %> <% if i == 1 || i == 7 || i == 14 %><!-- 1st, 7th, & 14th record --> display title, description & something else <% else %><!-- other records --> display only title <% end %> <% end %

Backbone outputing empty array for collection.models?

耗尽温柔 提交于 2019-12-23 02:36:14
问题 Having a problem where if I do apples = new Apples apples.fetch() console.log apples console.log apples.models console.log apples will out put the Apples Collection, with models: Array(10) listed inside the object. But, console.log apples.models outputs an empty array. Why does this happen? Thanks in advance. 回答1: Are you trying to console.log the collection right after executing the fecth() method or waiting for the callback to be executed by using apples.on('reset', function(){ console.log

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

故事扮演 提交于 2019-12-21 04:27:18
问题 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

how to load html file in Marionette .js + backbone?

对着背影说爱祢 提交于 2019-12-20 03:53:12
问题 I have one "test.html" in that I have this contend (whole html file have this contend). <h1>First page</h1> I need to load that contend in my div having id ="contend" using Marionette .js <div id="contend"> </div> could you please tell me how I will do that ? fiddle : http://jsfiddle.net/JQu5Q/16/ $(document).ready(function(){ var ContactManager = new Marionette.Application(); ContactManager.addRegions({ mainRegion:"#contend" }) ContactManager.on("start", function(){ console.log(

How to know if element is already in the DOM when creating new Backbone view

女生的网名这么多〃 提交于 2019-12-19 04:04:58
问题 here's the situation: When page is opened for the first time, it already has prepared DOM by server(php). If user has javascript turned on, then i want to convert my page to web app(or whatever you call it). As soon as Javascript is initialized, Backbone fetches collection from server. The problem is, that some of these fetched items are already on page. Now how can i mark those items which already are in the DOM? And how can i tie them up with the Backbone view? 回答1: Hooking up a Backbone

How do I get backbone to bind the submit event to a form?

好久不见. 提交于 2019-12-18 18:53:59
问题 I'm using the following code to create the view: LoginForm = Backbone.View.extend({ tagName :"form" ,id : "login-form" ,className :"navbar-form" ,initialize: function () { this.model = new StackMob.User(); this.render(); } ,render: function () { $(this.el).html(this.template()); return this; } ,events : { "change" : "change" ,"submit #login-form" : "login" } ,login : function( event) { event.preventDefault(); var self = this; this.model.login(true, { success: function( model) { app

Is it possible to stop Backbone “read” requests

前提是你 提交于 2019-12-18 11:45:37
问题 I have a backbone application that has a number of views. Switching between views triggers Ajax requests to get different collections. I would like to stop the current "read" ajax request if a new one is started. Is it possible? 回答1: Ok so here is what I did I am saving the the fetch requests in a variable app.fetchXhr = this.model.fetch(); In my router, I have a function that takes care of closing the views and rendering views. It also takes care of triggering any triggers needed for each

What is the difference between $el and el in Backbone.js views?

会有一股神秘感。 提交于 2019-12-18 10:08:11
问题 Can you please tell the difference between $el and el in Backbone.js views? 回答1: lets say that you do this var myel = this.el; // here what you have is the html element, //you will be able to access(read/modify) the html //properties of this element, with this var my$el = this.$el; // you will have the element but //with all of the functions that jQuery provides like, //hide,show etc, its the equivalent of $('#myel').show(); //$('#myel').hide(); so this.$el keeps a reference to your //element