I am facing a problem with variable scope…I do not want to complicate things,so for now I am going to be very general in my description since I am dealing here with a problem which relates to backbone.
Suppose I have 2 functions…function a and function b.
Function a is called first and function b is called secondly.
Ιn function b there is a value assignment in a global variable—this same variable is located inside function a
It would be reasonable to assume that once execution of function b ends…the value that was set there in the global variable will persist-in function a.
Meaning the global variable in function b will have the value from the assignment in function a.
Am I right or wrong?I hope I was clear…else I will restate the issue.
Outside of a function, if you use var varName = "this"; then it will be globally available to all functions. If you use varName = "this"; (without var), then it will be available only outside of functions.
INSIDE a function, if you use var varName = "this";, it will be available only to that function. If you use varName = "this"; (without var), it will be globally available outside the function.
Then…the parse function is called at line 9 which assigns a value at the global variable closed at line 10
My problem is that the value assigned above is not set at line 62…(the same global variable as mentioned above)
I miss something here but I cannot find what…
Maybe…**maybe…**in order for the variable assignment to take place in the render function…this render function must be called again…for the second time…after parse.
As it stands, your parse method isn’t modifying the response at all, it’s just passing it through unchanged (as the default method does). It seems like what you actually want to be doing in your parse method is this:
I tried the above but my appointments not even show in the calendar anymore…probably in order for this code to work I must make some refactoring,
Let us focus on the issue at hand,
var Events = Backbone.Collection.extend({
model: Event,
url: 'events',
parse: function (response) {
closed=response[0].closed_days;
package = 'test';
servstatus = response.servstatus || response;
staffstatus = response.stafstatus || response;
appointments = response;
return response;
}
});`
var EventsView = Backbone.View.extend({//σχετικό με το calendar view
closed:this.closed,
initialize: function () {
_.bindAll.apply(_, [this].concat(_.methods(this)));
},
render: function () {
console.log('clos',window.clos);
this.$el.fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,basicWeek,basicDay'
},
selectable: true,
selectHelper: true,
hiddenDays:this.closed,//here is the problm
editable: true,
ignoreTimezone: false,
select: this.select,
eventClick: this.eventClick,
eventDrop: this.eventDropOrResize,
eventResize: this.eventDropOrResize
});
},
I managed(with some tricks) to call render after parse is called,I cannot understand though whyhiddenDays()link does not take the value of this.closed