[mochikit] can log but unable to return value from addCallback
I can log the value, but it returns as undefined. var getOffice = function(county_id) { var d = loadJSONDoc('/office_from_countytype/'+ county_id +'/'); var off_id; d.addCallback(function (result) { off_id=result[0].fields['office']; log('got office id: '+ off_id); return off_id; }); } The log entry will show INFO: got office id: 14, but the function returns undefined. -- You received this message because you are subscribed to the Google Groups MochiKit group. To post to this group, send email to mochi...@googlegroups.com. To unsubscribe from this group, send email to mochikit+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/mochikit?hl=en.
[mochikit] Re: can log but unable to return value from addCallback
thanks for the response - I'll give this a try. I'm still trying to wrap my head around the concepts of deferred and callbacks On Nov 15, 2:45 pm, Fredrik fblomqv...@gmail.com wrote: You're confusing the return inside addCallback with the return from the outer getOffice function. --- modified example: var getOffice = function(county_id) { var d = loadJSONDoc('/office_from_countytype/'+ county_id +'/'); var off_id; d.addCallback(function (result) { off_id=result[0].fields['office']; log('got office id: '+ off_id); return off_id; }); return d; // --- ! } ... now, a user can get 'off_id' like this. var d = getOffice(country_id); d.addCallback(function(off_id) { log('got office id:', off_id); }); (since getOffice makes an asynchronous request any return from it must, by definition, also be asynchronous.) HTH // Fredrik Blomqvist On Nov 15, 7:04 pm, hotani hot...@gmail.com wrote: I can log the value, but it returns as undefined. var getOffice = function(county_id) { var d = loadJSONDoc('/office_from_countytype/'+ county_id +'/'); var off_id; d.addCallback(function (result) { off_id=result[0].fields['office']; log('got office id: '+ off_id); return off_id; }); } The log entry will show INFO: got office id: 14, but the function returns undefined. -- You received this message because you are subscribed to the Google Groups MochiKit group. To post to this group, send email to mochi...@googlegroups.com. To unsubscribe from this group, send email to mochikit+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/mochikit?hl=en.
[mochikit] Re: createDom option example please
Ok. Like I say, this is not very clear to me right now, and I'm trying to create an option list for a drop-down. Let me put up my shot-in-the-dark example, then maybe someone can correct me: // add a single value/text option to drop-down: OPTION(null, {'value': '123', 'text': 'some text'}); Trying to create this: option value=123some text/option and a bunch more if everything goes well I know that is completely wrong. This may be explained in the docs, but I'm not seeing it. The example for building a table element is not translating to an option. How does it know what element to use? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups MochiKit group. To post to this group, send email to mochikit@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/mochikit?hl=en -~--~~~~--~~--~--~---
[mochikit] Re: createDom option example please
Great, thanks Bob. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups MochiKit group. To post to this group, send email to mochikit@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/mochikit?hl=en -~--~~~~--~~--~--~---
[mochikit] Re: createDom option example please
And here is a real working example in all its glory: appendChildNodes($('id'), OPTION({'value':val}, txt)); where 'val' is an id from the database and 'txt' is its description. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups MochiKit group. To post to this group, send email to mochikit@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/mochikit?hl=en -~--~~~~--~~--~--~---
[mochikit] Re: createDom option example please
Good to know, thanks. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups MochiKit group. To post to this group, send email to mochikit@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/mochikit?hl=en -~--~~~~--~~--~--~---
[mochikit] really basic example?
Up until this morning, I thought I knew my way around JavaScript. Looking at the docs for MochiKit has proven otherwise. All I want is a basic example of a call to a json file, and output. The docs are shooting right over my head and I still don't get what deferred really means. There is a 450 line beast I've been digging through that is the 'sortable tables' example, but I was hoping for a 5 liner. You know, like get data show data. Anyone? Maybe there is some documentation somewhere that I'm missing? Just don't know how to start here... So far, I have this: var d = loadJSONDoc(/myapp/ajax_test/); (Django is spitting out the JSON btw) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups MochiKit group. To post to this group, send email to mochikit@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/mochikit -~--~~~~--~~--~--~---