The binds property still isn't doing the trick for me. All I'd like to be able to do is run a mootools Request.JSON to the server and then assign the data returned from the server to an instance variable in my javascript class. Is there any generalized example for doing this? I'm pretty sure i'm binding correctly because I can see what the current values of the variables are, I just can't assign new data, and have that data stick.
On Aug 25, 12:37 pm, reaktivo <[email protected]> wrote: > You could change it to this: > > var Demo = new Class({ > Binds: ["updateDemo", "save", "success"], > save: function() { > var req = new Request.JSON({ > url: "/demos.json", > method: "post", > data: {"demo[name]":this.name, > "authenticity_token":this.auth_token}, > onSuccess: this.success > }).send(); > }, > success: function(d) { > this.updateDemo(d.demo.id, d.demo.name); > this.id = d.demo.id; > }, > updateDemo: function(id, name) { > this.id = id; > this.name = name; > } > > } > > updateDemo was not being "binded". > > On Aug 25, 12:24 pm, drew n <[email protected]> wrote: > > > > > The following code requests information about an object, and then > > tries to set a couple class variables based on the data returned from > > the request. > > > var Demo = new Class({ > > save: function() { > > var req = new Request.JSON({ > > url: "/demos.json", > > method: "post", > > data: {"demo[name]":this.name, > > "authenticity_token":this.auth_token}, > > onSuccess: function(d) { > > this.updateDemo(d.demo.id, d.demo.name); > > this.id = d.demo.id; > > }.bind(this) > > }).send(); > > }, > > > updateDemo: function(id, name) { > > this.id = id; > > this.name = name; > > } > > > } > > > I've got "this" binded properly because I can access the updateDemo > > function properly but I can't seem to be able to set variables from > > within the updateDemo function, or the onSuccess function. > > > If I create a demo class and then try and access the "id" variable, it > > returns as undefined. What am I doing wrong? > > > Thanks in advance!
