PDA

View Full Version : custom function



GeXus
28 Apr 2007, 8:22 AM
I have a situation where onclick I pass an ID to a function I created. I want to get this to pass inside the Ext.onready so I can use it in an ajax call. Any idea how I would create a custom function that I can call that's inside the Ext?

Thank you!

Animal
28 Apr 2007, 9:41 AM
Can you explain a bit better, or post some code?

GeXus
28 Apr 2007, 5:32 PM
Sure, I have a list of items that are in html, each one has the following



<a href="#" onClick="myFunction('55');">Item 55</a>
I want to be able to call this function inside of Ext.onReady, specifically in here



function addUnderResult(btn, text, cat_id){

//My Function
function myFunction(id){
cat_id = id;
}


var CategoriesInside = Ext.get("CategoriesInside");
CategoriesInside.load({
url: "categories.php",
params: "name="+text+"&cat_id="+cat_id+"&type=add_under",
text: "Updating..."
});
CategoriesInside.show();
};
This is the result for a Ext.MessageBox I have, so it will be something like this.. First click on the item that has the "myFunction" that sets the selected ID, then I have a button that calls the Ext.MessageBox, then that selected ID is associated with the value which is typed in the messagebox.... Make sense?

Thanks a lot for your help!

dfenwick
28 Apr 2007, 5:43 PM
Sure, I have a list of items that are in html, each one has the following



<a href="#" onClick="myFunction('55');">Item 55</a>
I want to be able to call this function inside of Ext.onReady, specifically in here



function addUnderResult(btn, text, cat_id){

//My Function
function myFunction(id){
cat_id = id;
}


var CategoriesInside = Ext.get("CategoriesInside");
CategoriesInside.load({
url: "categories.php",
params: "name="+text+"&cat_id="+cat_id+"&type=add_under",
text: "Updating..."
});
CategoriesInside.show();
};
This is the result for a Ext.MessageBox I have, so it will be something like this.. First click on the item that has the "myFunction" that sets the selected ID, then I have a button that calls the Ext.MessageBox, then that selected ID is associated with the value which is typed in the messagebox.... Make sense?

Thanks a lot for your help!

Give your anchors IDs. Then, instead of providing an onClick handler on the tag, assign the handlers inside your onReady with:


Ext.get('id55').on('click',myFunction);

You could potentially link your function to your global scope, but it's not very clean and you'll still end up dealing with multiple scoping issues.

GeXus
29 Apr 2007, 10:54 AM
Hmm.... well the ID's are dynamic and there will be hundreds... so for this part



Ext.get('id55').on('click',myFunction);


How would I know what id to put in there?

dfenwick
29 Apr 2007, 2:22 PM
Hmm.... well the ID's are dynamic and there will be hundreds... so for this part



Ext.get('id55').on('click',myFunction);


How would I know what id to put in there?

You wouldn't unless the IDs have some structure. You could potentially use DomQuery to search for those IDs based on criteria, but you'd have to be really careful doing that.

Animal
29 Apr 2007, 11:57 PM
So basically, you want to "intercept" clicks on a bunch of <a> tags?

Best thing would probably be to give those tags that you want to intercept the clicks for a CSS class, then use a document click handler.

In that handler, check whether the target has that class, and if it does, perform appropriate processing - and stop the event so that the page doesn't actually navigate to "#" (The document top).