I'm trying to attach functions to certain elements (using JQuery), and the elements are dynamically created. I'm using a loop, so I have to do something to use the correct variable names in the functions. One other thing: I am using values retrieved from Ruby, and I'm trying to call a Ruby function.
So here's the line that crashes my app:
addedItem.find("#repoRemove_" + repo.name).click(function(name) { return function() { window.p2pdoc_settings.testout(name); }; }(repo.name));
Strangely enough, I can crash it with just this single line as well:
repo_name = repo.name;
But the following lines actually work (though you'll notice they don't handle my needs):
addedItem.find("#repoRemove_" + repo.name).click(function(name) { return function() { window.p2pdoc_settings.testout(name); }; }("def"));
addedItem.find("#repoRemove_" + repo.name).click(function(name) { return function() { alert(name) }; }(repo.name));
I'm ready to try anything else. I've tried "new Function()"; I've tried putting the functions and variables in all kinds of scopes; I've tried different combinations of nesting for the functions. But I'll try whatever brainstorms you've got. Thanks.
3 Answers
Nope. Erasing my dist directory doesn't always work.
The answer has something to do with the application settings which are stored in ~/Library/Application\ Support/Titanium/appdata/ here on my Mac. Each application has a folder based on the application ID, ie. where it suggests "com.companyname.appname" when you set up a new project; since I was developing on the same project in different places as things change and I test (eg. source control, Studio vs Developer), I guess that mucked things up.
Creating a new app with a different ID and then copying source files over (except tiapp.xml and manifest files) now lets me work without crashing. (BTW, it wasn't enough to move the old appdata folder out of the way.)
OK, this is interesting: in a different crash situation I add the following (to print the moreInfo result of a Ruby call to the console) in just the right location and it doesn't crash any more:
Titanium.API.print("results: " + moreInfo + "\n");
Well, I've found ways to work around the problems with the Ruby interface. They're ugly, but they work.
Your Answer
Think you can help? Login to answer this question!