backbone-views

Render a View of Backbone Model returns undefined

廉价感情. 提交于 2019-12-12 01:43:22
问题 Lets say i have a JSON like this: JSON example, my json is validated on jsonlint and it works. json_object = { "texts_model": { "hello": "hola", "icon_text": "Icon!" }, "collection_vias": { "text": "hola", "icon_text": "Icon!" } }; I have made a Collection that parse the contents of the json and generates model and collections from this json. App.TemplatesCollection = Backbone.Model.extend({ model: App.TemplateModel, url: TEMPLATES_SERVICE, initialize: function(){ this.fetch({ success:

Backbone - Change tagName on condition

≡放荡痞女 提交于 2019-12-11 00:22:27
问题 I'm trying to switch the tagName of a Backbone view based on a condition. I initially thought I would be able to set a default tagName of say 'div' (I realize this is the default), then in the view's initialize function, check for the condition and change the tagName but this unfortunately didn't work. Here is my view code (written in coffeescript): class Test.Views.ListView extends Backbone.View attributes: {"data-role": "listview"} className: 'row' tagName: 'div' initialize: -> if @options

detecting backbone model changes to enable save button of form and update model

戏子无情 提交于 2019-12-11 00:04:34
问题 MY simple form template is like this <script type="text/template" id="template"> <form id="myForm " > <fieldset> <label>Name</label> <input type="text" id="name" name="name" /> <label>Age</label> <input type="text" id="age" name="age" /> <input type="hidden" id="id" name="id"/> </fieldset> <a id="save" disabled >Save Changes</a> My bakbone view is as follows: myView = Backbone.View.extend({ template: _.template( $("#template").html() ), events: { "click #save" : "save", }, bindings: { '#id':

CompositeView slow to render items for large result set Marionette

删除回忆录丶 提交于 2019-12-10 17:22:30
问题 I'm currently working on a project that's using .NET MVC on the back end and Backbone (v1.1) with Marionette JS (v1.8.5) on the front end and I am experiencing some performance issues when trying to render a Composite view with 200 results or item views. I first came across this SO post of a similar issue which helped me get a newer version of marionette (v1.8.5). Handlebars templates are being used to show a html table with each itemView being wrapped in a tbody (this has a more complex

Display a view using an existing rendered HTML with Backbone Marionette

随声附和 提交于 2019-12-10 09:24:10
问题 I am having an application layout like the one attached. The upper panel is already to the page (i.e. in the server's HTML response). While the user interacts with the elements in that panel the content of the dynamic panel below changes accordingly. I've studied Backbone Marionette various View types and Region Manager. But I still can't figure out a way to implement this. I need to capture events from the already rendered elements and change the dynamic content accordingly. As I understand,

How can I pass a parameter into a Backbone.js view?

主宰稳场 提交于 2019-12-09 19:30:37
问题 I'm trying to pass a parameter into a Backbone.js view, but I'm having trouble doing it. I have a Backbone view as follows: var DataTypesView = Backbone.View.extend({ events:{ 'click .datatype': 'add' }, initialize: function(){ console.log(this.magic); this.render(); }, render: function(){ console.log('printing template'); console.log(this.templateString); etc. }}); Later, I crate the view as follows: dataTypesView = new DataTypesView({magic:true,el:$('#dataViewSpace'),templateString:'

How to pass arguments to functions binded in events object in backbone.js

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-09 12:43:05
问题 I need to have arguments to the functions used in the events object in Backbone. var DocumentRow = Backbone.View.extend({ tagName: "li", className: "document-row", events: { "click .icon": "open", "click .button.edit": "openEditDialog", "click .button.delete": "destroy" }, render: function () { // do something } }); Now let the definition of open be: function open(id) { if (id) { // do something } else { // do something else } } I will call open from another function and will pass id when I

Backbone: Adding a model to Collection and render a View

微笑、不失礼 提交于 2019-12-08 12:00:26
问题 I'm building a simple Backbone app where I mainly have a view with a list of books (book name + cover image) and another view where I want to add new books to the list. When I use a sample data the view with the books renders properly, but when I try to add books to the list it doesn't work and I don't know which is the problem. Here is the JSFiddle http://jsfiddle.net/swayziak/DRCXf/4/ and my code: HTML: <section class="menu"> <ul class="footer"> <li><a href="">List of Books</a></li> <li><a

Backbone - Create Multiple Models in Collection - serverside

浪子不回头ぞ 提交于 2019-12-08 05:00:33
问题 I provide a form for users to upload their own data. I use ajax-form-submit and then parse the data to create numerous models (one per row in uploaded csv). Now, I want to create models into a predefined collection. I can use add which takes an array of models but unfortunately, it does not send PUSH at server side. I know I can iterate and create .create for each model but let's say I have 10k models, it would create 10k calls. Sounds unreasonable. Did I miss anything? The other way is to

how to delegate a “load” DOM event?

半城伤御伤魂 提交于 2019-12-07 06:40:37
问题 I would like to call a function when a "load" event is triggered: events: { "load #eventPicture" : "_resizeHeaderPic" } I don't want to do something like this.$("#eventPicture").on("load", _resizeHeaderPic); because I have a lot of views (it's a Single Page App ) and I could go back to show another view before the image was loaded. So, if I then come back to this view I would have two listener for that "load" event. Right? By putting everything in my events hash , I can undelegate properly.