backbone-views

Backbone outputing empty array for collection.models?

假如想象 提交于 2019-12-07 03:53:26
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. Shaked KO 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(this.models);} ,this); ? I just tried this and it worked out for me. Backbone collections have a

How can I dynamically set a className for a Backbone.js view based on it's model attributes?

 ̄綄美尐妖づ 提交于 2019-12-06 19:54:48
问题 Basically what I need is to do something like this App.CommentView = Backbone.View.extend({ className: function() { if (this.model.get('parent_id')) { return 'comment comment-reply'; } else { return 'comment'; } }, The problem is, that at the function passed to className is executed in context of the html of the view template, so I can't call this.model . Is there any way I can access the model at this point in the rendering process? Or do I need to set the class later, for example in the

Backbone - Create Multiple Models in Collection - serverside

大憨熊 提交于 2019-12-06 16:40:44
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 accept multiple models at server and use .ajax calls and then add manually to the collection for UI

Typescript Backbone View Events do not fire

孤街醉人 提交于 2019-12-06 15:01:31
I'm trying to make a simple view to test with backbone. I've started with events, but no one fires. Why ? I've made already other things with backbone like routing etc. without problems. Thanks for your time. My backbone definitions are from -> this source <- module Views { export class MenuView extends Backbone.View { constructor(viewOptions?: Backbone.ViewOptions) { super(viewOptions); } el = document.body; events = { "click #Btn-Start": "navigate", "click #Btn-Software": "navigate", "click #Btn-Anderes": "navigate", "click #Btn-Impressum": "navigate" }; initialize() { console.log(

How do you create Backbone views with an 'el' that was dynamically created?

回眸只為那壹抹淺笑 提交于 2019-12-06 14:17:55
问题 I have two views -- an OverlayView and a StoryView. The StoryView needs to get appended to the OverlayView (both are created dynamically). I create the #overlay div dynamically in the OverlayView, but when I set the 'el' of the StoryView to #overlay, this.$el of StoryView is an empty array. The #overlay div definitely exists in the DOM by the time the StoryView is created. How do I get the StoryView to recognize the dyanmically created #overlay as its 'el'? Am I correct in assuming the 'el'

Event handling between views

匆匆过客 提交于 2019-12-06 06:29:46
问题 Ok I have a layout like the one in this pic: The table in the upper part of the screen is made by: MessageListView define(['backbone','collections/messages','views/message'], function(Backbone, MessageCollection, MessageView) { var MessageListView = Backbone.View.extend({ el: '#messagesContainer', initialize: function() { this.collection = new MessageCollection(); this.collection.fetch({reset:true}); this.listenTo( this.collection, 'reset', this.render ); this.table = this.$el.find("table

how to delegate a “load” DOM event?

 ̄綄美尐妖づ 提交于 2019-12-05 11:06:44
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. But it seems that "load #eventPicture" does not work. Any suggestion? Vitalii Petrychuk You cannot track

How can I dynamically set a className for a Backbone.js view based on it's model attributes?

喜你入骨 提交于 2019-12-05 01:29:48
Basically what I need is to do something like this App.CommentView = Backbone.View.extend({ className: function() { if (this.model.get('parent_id')) { return 'comment comment-reply'; } else { return 'comment'; } }, The problem is, that at the function passed to className is executed in context of the html of the view template, so I can't call this.model . Is there any way I can access the model at this point in the rendering process? Or do I need to set the class later, for example in the render function? This sounds like a job for model binding. App.CommentView = Backbone.View.extend({

How do you create Backbone views with an 'el' that was dynamically created?

核能气质少年 提交于 2019-12-04 20:24:13
I have two views -- an OverlayView and a StoryView. The StoryView needs to get appended to the OverlayView (both are created dynamically). I create the #overlay div dynamically in the OverlayView, but when I set the 'el' of the StoryView to #overlay, this.$el of StoryView is an empty array. The #overlay div definitely exists in the DOM by the time the StoryView is created. How do I get the StoryView to recognize the dyanmically created #overlay as its 'el'? Am I correct in assuming the 'el' should be the 'parent' container to which the view is appended? Should the 'el' of the OverlayView

Backbone.js view instance variables?

时间秒杀一切 提交于 2019-12-04 18:09:03
问题 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: