render:function(output){
_.each(output, function(i){
p=i.name;
});
$(this.el).append(p);
}
here i am getting output in the form of json….i have 100 names…and i want to append it one after the another…in this case i get one name….
if i put like this…
render:function(output){
_.each(output, function(i){
p=i.name;
$(this.el).append(p);
});
}
inside the each loop nothing come…
do i need to make 100 variable like p here or is there any other way…
You need to provide the context, i.e. this. “this” is the reference to the current object you are working in. However, when you are calling a different function from within your current object, you are loosing the reference to your current object. Basically, this then refers to the the function. But you can easily fix this.
Either by adding this as an argument to the function call:
Or by providing this via a helper variable
I would go for option 1