PDA

View Full Version : Id conflicts in multiple tabs



arpeggian
24 Jul 2012, 1:52 AM
Dear all

I'm building extjs-based applications. My application has many links in the navigation, and every link clicked will create a new tab in contentPanel. this my tree listener code:


url = sharedData.rootDir + data.url +'?id='+node.getId();
if (node.isLeaf()) {
var tab = contentPanel.add({
// we use the tabs.items property to get the length of current items/tabs
title: node.get('text'),
id: node.getId(),
closable: true,
forceFit:true,
autoScroll: true,
layout:'fit',
autoLoad: {
//url: sharedData.rootDir + "app/gallery/galleryFoto.php",
url: url,
scripts: true,
listeners: {
beforeload: function(){ viewport.setLoading(); },
load: function(){
viewport.setLoading(false);
},
exception: function(){
Ext.Msg.alert('Error','Halaman yang anda maksud tidak ada');
viewport.setLoading(false);
}
}
},
listener: {
activate: function(){
alert('activate');
contentPanel.items.each(function(c){c.disable(); alert(c.getId());})
},
focus: function(){
alert('focus');
contentPanel.items.each(function(c){c.disable(); alert(c.getId());})
}
}
});
if(tab)
contentPanel.setActiveTab(tab);
contentPanel.items.each(function(c){ if (c.getId() != tab.getId()) c.query('input').disable(); })
}
}

},

The problem is, when a single tab (A) there is a component with id: 'MyField' and in another tab (B) there is also a component with the same id, the id: 'MyField' .. then there is the field 'MyField' in tab A will disappear, and the layout or arrangement of B field in the tab would be a mess.


if there is no other way than to use a unique id for each component, although different tab. or any other means, such as adding listeners when ditambahakan tab, then the other tab is disabled? or multiple fields / components is disabled?


please help me .. sorry for my bad english. thank you


regards

Farish
24 Jul 2012, 2:58 AM
Instead of id, use itemId (http://docs.sencha.com/ext-js/4-0/#%21/api/Ext.AbstractComponent-cfg-itemId) (check out the API Docs for details)

arpeggian
24 Jul 2012, 9:33 AM
Instead of id, use itemId (http://docs.sencha.com/ext-js/4-0/#!/api/Ext.AbstractComponent-cfg-itemId) (check out the API Docs for details)

thanks for the reply. if itemid will not conflict? ok, there is a statement of the itemid is scoped locally to the container ... itemid if I can use to store the identifier of? for example, there is a grid, form, store .. (crud) .. if I can use to perform loadRecord itemid from store?


thank you Farish. :)

dbrin
24 Jul 2012, 9:52 AM
Or don't use IDs at all and use ComponentQuery to target your components. You can set any arbitrary property and use query/up/down methods passing in [property=value] identifiers of your components.

arpeggian
24 Jul 2012, 12:17 PM
Or don't use IDs at all and use ComponentQuery to target your components. You can set any arbitrary property and use query/up/down methods passing in [property=value] identifiers of your components.

thanks for the replies,


attractive solution, but if in that way I will lose loadRecord from store to feature my form? id identifies the default?

dbrin
24 Jul 2012, 12:22 PM
not really, you don't loose anything you just do things a little differently. you still need to identify records. So record ID is ok - just don't use it to set other component's IDs.