This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I use Backbone & Marionette for my webapp,
I Have a collection of tracks, when a track is added and when the player don't read any track, I want put "played" style to itemView, or "paused" to the track added on the cue.
So I want to add a class for each new Backbone model.
When I add a model, the class is added to the previous element, but not on the newest.
This is my CompositeView :
var trackListYTView = Marionette.CompositeView.extend({
template: "#playlist",
id: "trackList",
itemView: trackView,
itemViewContainer: "tbody",
initialize: function(){
this.bindTo(this.collection, "add", this.modelAdded);
},
modelAdded: function(model){
if(status) this.$('#status').addClass('icon-pause');
else this.$('#status').addClass('icon-play');
}
I think "this" is not the good selector for the new itemView.
Thanks for helps, Luca
I think your problem is the selector - #status. The element id should be unique. You should not have multiple elements with same id. Use a class selector, for example '.statusClass', instead of '#status'.
Related
In my current app, i am getting more than 40 records with images. In single record i have 6 fields to display include image field. Right now i am using Dataview to display the records whether Dataview will impact my app performance if i get more than 100 records from server ? or i should go for Listview ?
sample snipplet
itemList:function(){
return [
"<tpl>",
"<div class='Container'>",
"<div class='OfferImgContainer'><img class='offerImg' src={thumbnail}></div>",
"<p>",
"<div class='offerCategory'>{category}</div>",
"<div class='offerheader'>{title}</div>",
"<div class='offerContent1'> {content}</div>",
"<div class='offerContentfind'>Find out more <i class='offerArrow fa fa-chevron-right'></i></div>",
"</tpl>"
];
},
List does quite a bit more than DataView to support infinite dataset. List will render slower but during runtime with as many records in the store it will handle it a lot better. If you try to use DataView with a thousand records in the store, the device will struggle to handle that many DOM nodes so the List can handle this. If you don't need the features List brings to the table, then just use a DataView and style it the way you need it to look.
ListView :
Can handle multiple records
Good support for basic listing
Dataview:
Support others sencha components inside the dataview by extending 'Ext.dataview.component.DataItem'
Good to have less no of records in order to avoid performance issue
I am creating a survey app. In this a question can have multiple answers. So I am storing answers in a collection. I am using Backbone.CollectionBinder to render views by passing view class. Each view have "Remove Answer" link.
Lets say there are 3 answers added to collection. Now if I remove 1st answer it always gives me last model in that view class. So the problem is it always gives me last model inside answer view.
We need some more information. The docs (http://backbonejs.org/#Collection-remove) state that the removed model is returned from the collection. I've used it heavily without issue. It sounds like your reusing the same view or iterating incorrectly. Please post some code.
I got the answer of my question from following post
http://lostechies.com/derickbailey/2011/10/11/backbone-js-getting-the-model-for-a-clicked-element/
I'm trying my first backbone project and I've stumbled into this:
I have the MODEL and VIEW of the day (with events, layout, etc). What is the best to model the MONTH to contain a collection of days (a collection or something else - not sure) and in addition to this the model month should have some extras (like: buttons - next/prev month, etc)
can I do (something) like this:
month = Backbone.model.extend({
model: {
extras: button_model,
days: day_collection
}
});
?
Or is there a better way?
Thanks
I think you're getting the concept of models and collections mixed up. Think of a model as a singular instance of something such as, in your example, a day. If we want to get a group (or collection) of days then we use a collection to store them in.
We set up the Backbone model like so:
DayModel = Backbone.Model.extend({
});
Then we create a Backbone collection, clearly specifying the model we want to use:
MonthCollection = Backbone.Collection.extend({
model: DayModel
});
We can create a new DayModel with:
monday = new DayModel({ name: "Monday", dayOfMonth: 12 });
name within the braces is an attribute we are giving to the new DayModel monday.
These attributes can be retrieved using:
monday.get('dayOfMonth');
which would return 12
We can now create an instance of the MonthCollection:
july = new MonthCollection();
To add models to the collection (days to the month) we simply use this:
july.add(monday);
See this jsFiddle for further reference.
You mention buttons being stored in your models. In my opinion it would not be best to use models to store elements such as this. Instead you would use a Backbone view which you would populate with model data and create buttons using the ID or any such uniquely identifying attributes so that the month you want will be selected.
Please read the Backbone documentation to give you a deeper understanding of Backbone.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I'm using CakePHP, and trying to pull data from a table outside my current controller. The only thing I can find online is about using associations and belongsTo and such, however these two items shouldn't be related. I simply want to pull data from another table at will.
You could also use the loadModel inside your functions.
$this->loadModel('User', 2);
$user = $this->User->read();
Well if you want to access different model (not the related to the controller) you can use
class SomeController extends AppController {
var $uses = array('Model1', 'Model2');
// and then later in the code you can use them like this
function index() {
$this->Model1->doStuff;
$this->Model2->doStuff;
}
}
you can use
$user=App::Model('User');
$user->find('all');
either
//only controller
$this->loadModel('MyModel');
$res = $this->MyModel->find(...)
or
//everywhere
$this->MyModel = ClassRegistry::init('MyModel');
$res = $this->MyModel->find(...)
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I have 3 tables: users, images (foreign key to user_id), comments (foreign keys: user_id and image_id)
Can somebody explain me or send me link to good tutorial how to work with database?
I mean e.g.:
1. I wants to take all Images which have any comment in Comments table. In SQL: select i from Images i, Commets c where i.id=c.image_id???
Can You explain me how can I access from one controller to another Model?
I was trying in Images controller:
$data = $this->Image->query('Select * from Images i, Comments c where i.id=c.image_id');
And in view: $image['id'] but I have error:Undefined index: id [APP\views\images\commented.ctp,
SO it does not work:/
How can I delete Image and all its comments? I used Zend and I get used to it and I have no idea how to do the same thinks in cakePHP :/
Can somebody explain me how to work with database in this cakePHP I know there are find, findAll etc functions but all of them are from a controller level ex. $this->Image->find() etc...
I need better tutorial than the basic cakePHP cookbook :/. I am open for any sugestions.
Regards,
You reference models in the controller in one of many ways. The two common ways are with the uses variable at the top of the controller:
var $uses = array('User','Image');
Or you can put it inline in your functions:
$this->loadModel('Image');
$this->Image->find('all'); ...
In addition, if you have the models linked by a foriegn key, you can even call it like:
$this->User->Image->find('all');
Once you get the hang of how CakePHP structures things, it makes it very clear.
So for your sql statement in the question, you could do something like the following from the users controller:
class UsersController extends AppController {
var $name = 'Users';
var $uses = array('User','Image','Comments');
function {my_function_name}() {
$this->Images->recursive = 1;
$images = $this->Image->find('all');
}
}
Now, as long as your relationships are correct in the model, the recursive function will build the images array with all of the comments attached to it.
array(
[Image] => array(
image data,
[comments] => array(
[0] comment data,
[1] comment data,
[2] ...
)
)
)
I hope that at least pushes you in the right direction. Happy coding!