backbone.js

How to display Backbone nested attribute using Eco?

微笑、不失礼 提交于 2020-01-25 04:33:06
问题 I've followed Ryan Bates' example on Backbone.js to start a project using Backbone + Eco. It's great. However, I'm stuck trying to display a nested attribute. For example, I'm trying to do this: <%= @stream.user.get('name') %> in index.jst.eco and I'm getting Uncaught TypeError: Cannot call method 'get' of undefined However, I can get <%= @stream.get('stream_type') %> to work. Here's the REST API data: [ : { : : "id":"5004095283de4ca9ff000005", : : "created_at":"2012-07-16T12:30:10Z", : :

Backbone router creates multiple views which causes multiple events to bind to the same view

*爱你&永不变心* 提交于 2020-01-24 21:15:30
问题 I'm new to backbone.js and trying to understand how routes, views etc works and now I have a problem with events building up for the same view. here is a clip that will show you exactly what I mean. http://screencast.com/t/QIGNpeT2OUWu This is how my backbone router looks like var Router = Backbone.Router.extend({ routes: { "pages": "pages", } pages: function () { var page_view = new PageView(); } }); So when I click the Pages link I create a new PageView and this is the code I'm using

Did backbone collection automatically parse the loaded data

放肆的年华 提交于 2020-01-24 20:25:18
问题 Try to use backbone collection to initialize grabbing the json data, but turns out the data is empty. Does backbone collection automatically parse the json data to the model or we have to manually parse it? var Book = Backbone.Model.extend({ title:"", isbn:"", img:"" }); var Books = Backbone.Collection.extend({ model:Book, url:'latest.json', // parse:function(data){ // console.log(data); // }, initialize: function(){ this.fetch(); } }); Edited to add in my sample json, I validate with

backbone.js - filtering a collection with the value from a input

痞子三分冷 提交于 2020-01-24 19:41:06
问题 I'am searching for a way to filter my backbone collection with the value from a input field - to achieve this, I defined an event listener with the view ("keyup input.searchBookmark": "search"): window.BookmarksListView = Backbone.View.extend({ events: { "keyup input.searchBookmark": "search" }, el: $('#bookmarksList'), initialize: function() { this.model.bind("reset", this.render, this); this.model.bind("add", function(bookmark) { $('#bookmarksList').append(new BookmarksListItemView({model:

backbone.js not picking up model context

一世执手 提交于 2020-01-24 13:14:05
问题 Please see the following fiddle. HTML <script id="person" type="text/x-handlebars-template"> <div>Title : {{title}} </div> <div>First Name : {{firstname}}</div> <div>Last Name : {{lastname}}</div> </script> <div id="people"></div> JS (function ($) { var personTemplate= Handlebars.compile($("#person").html()); var Person= Backbone.Model.extend({ title: null, firstname : "", lastname : "" }); PersonView = Backbone.View.extend({ tagName: "div", template: personTemplate, render: function () { $

Backbone.js link file to model

谁都会走 提交于 2020-01-24 07:05:30
问题 I am creating a web application using django and backbone.js. The problem is I need to upload files to the server. How do I link the backbone model with a file? Thus when I execute model.save() the file is uploaded to the server. EDIT: just to make things clear. What I want to do is I want to link a input file box with the backbone model. So when the user selects a file from his/her computer I should be able to link that file with the backbone model. And when I call the model.save() in the

_.pluck of Backbone collection not working

戏子无情 提交于 2020-01-23 17:46:44
问题 I have this model - class pt.SearchResultModel extends Backbone.Model defaults: id:"", image:"", colour:"" I am trying this - _.pluck(resultsCollection,'id') But it keeps returning undefined - not sure what's going on. What syntax error am I making? 回答1: The Underscore array methods are embedded (so to speak) into Backbone collections. You can call them directly on them: resultsCollection.pluck 'id' In most of the cases you could also use the Underscore methods over the collection's models

Templating using RequireJS (text.js plugin) and Underscore

时光总嘲笑我的痴心妄想 提交于 2020-01-23 15:39:05
问题 Need some opinions on the best way to manage templating in Underscore. I'm building a Backbone app and using Underscore to manage the templates. I started off by doing something like this in a 'template.js' file. templates = { template1: '<h1>Some HTML</h1>', template2: '<h1>Some more HTML and a <%= variable %></h1> ... } This gets messy. Fast. So, I looked into RequireJS's text plugin and that makes it much cleaner. Now, I have a bunch of HTML files, and I essentially store it into my

How to test AntiForgeryToken in MVC4 with backbone Single Page Application

落花浮王杯 提交于 2020-01-23 11:09:11
问题 I am having problems getting Microsoft's MVC's [ValidateAntiForgeryToken] to work with a Single Page Application (SPA) written using Marionette & Backbone. The problem seems to be that the MVC [ValidateAntiForgeryToken] method fails to see the token we send as part of the JSON. We thought it was because the token had to be in the Forms part of the reply but MrOggy85 says that isn't a problem (see his answer below). The code is in my api controllers, which use AttributeRouting, which we assume

Is there a rule of thumb to decide when to use trigger or triggerMethod in Backbone.Marionette?

左心房为你撑大大i 提交于 2020-01-23 05:28:21
问题 I'm playing a bit with Backbone.js and Backbone.Marionette and I would like to know what's the difference between trigger and triggerMethod . In particular, is there any rule of thumb to decide when use the former or the latter? In my mind events, for example, are useful to communicate between a DOM element and its view. triggerMethod is used in Marionette to update in cascade different components, e.g. a layout calls the show method to its children (children respond to onShow ). So, for me