Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

[dojo] dom query question

Status
Not open for further replies.

iza

Programmer
Apr 4, 2000
1,804
0
0
FR
hi [bigsmile]

I am kind of new to dojo and I have a weird problem using it ...

My goal is to show some search results.

So I build a store, query it and display the results by adding a new div for each result :
JavaScript:
var adresseStore;
require([
	         "dojo/dom", 
	         "dojo/store/Memory",	          
	         "dojo/dom-construct",
	         "dojo/query",
..
	     ], 
function(dom, Memory, domConstruct, query){
  ...		
  var container = dom.byId("chefDiv")
  adresseStore = new Memory({data:data, idProperty: "myId"});
  adresseStore.query().forEach(function(item, i){
    addRow(item, container)
    // do something with the index
  });
where addRow basically calls
JavaScript:
domConstruct.create("div",{...,class: "adresse",...}, container);

and it works fine [thumbsup] - i've got something like
HTML:
<div id="chefDiv">
  <div class="adresse" ...>...</div>
  <div class="adresse" ...>...</div>
</div>

Now, I want to open a window when one clicks on an "adresse" div - I add
JavaScript:
query(".adresse").on("click", function(){
// do stuff and open a window
}
and it still works fine [2thumbsup]

Great !!! how about adding a button that will hide non valid results ? let's go :
first add a
JavaScript:
query(".sltValide").on("click", function(){
  domConstruct.empty("chefDiv");
  adresseStore.query({validite:"V"}).forEach(function(item, i){
    addRow(item, container)
    // stuff with i
  }); // foreach
}); // sltValide
everything displays well, I still have my
HTML:
<div id="chefDiv">
  <div class="adresse" ...>...</div>
  <div class="adresse" ...>...</div>
</div>
with the data I want to display, I'm happy [bigcheeks]...


... that is, until I click on a div to open the window ... [sadeyes]

the
JavaScript:
query(".adresse").on("click", function()
never fires

because
JavaScript:
query(".adresse")
doesn't return anything [hairpull]

anyone has a clue ? [orientalbow]
i'm stuck :-/

 
the answer is to fully qualify the query
Code:
query("#chefDiv").on(".adresse:click", function() {
			    // this works as a charm
});
[flowerface]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top