I've tried many things and I've read a lot of ways to do it but I can't make it work in my code. The thing is I want to iterate over each <li>
to test if the text of <span class="state">
is running or existed then remove the class hide of a button.
So there is my HTML code:
<template name="controlPanel">
<p>Start, stop and pause containers from this website</p>
<input type="button" id="infosRunning" value="Get running containers infos">
<!-- show all running containers -->
<div>
{{#if wantInfos}}
<ul class="container">
{{#each infos 'running'}}
{{> container}}
{{/each}}
</ul>
{{/if}}
</div>
<!-- ///////////////////////////////////// -->
<input type="button" id="infosStop" value="Get stopped containers infos">
<!-- show all running containers -->
<div>
{{#if wantInfosStop}}
<ul class="container">
{{#each infos 'exited'}}
{{> container}}
{{/each}}
</ul>
{{/if}}
</div>
<!-- ///////////////////////////////////// -->
</template>
<template name="container">
<li class="liContainer">
<div>
<h3>{{nameContainer}}</h3>
</div>
<div id="textContenu">
<span>ID: {{idContainer}}</span>
</div>
<div>
<span class="state">State: {{stateContainer}}</span>
</div>
<button type="button" class="stop hidden">stop this container </button>
<button type="button" class="start hidden">Start it ! </button>
</li>
</template>
And then in container.js I do that :
stopOrStart = function(){
$('.liContainer').each(function(i, obj) {
state = $(this).find('.state');
if(state.text().includes("running")){
$(this).find('.stop').removeClass('hidden');
}else{
$(this).find('.start').removeClass('hidden'); }
});
}
Template.container.onCreated(function containerOnCreated() {
stopOrStart();
});
But it only display the button for the first <li>
:
Someone could help me to figure out why I can't iterate over each "container" ?
`and I have 2 maybe the problem comes from here..
– Jerome Jan 04 '17 at 07:14