I have 2 list groups. The second is based off json data and filtered(2 if statements in the code)
This fiddle https://jsfiddle.net/andernathan/fL3cwoa2/32/ is a very simplified version of what I'm trying to do.
when you click on "Howdy" the second list shows "Howdy there" and "Howdy they're". When you click on "Howdee", I would like the second list to show just "Howdy their" (my second "if" statement)
Thanks...as always!
const activities1 = [];
const activities2 = [];
var json = {
"Tasks": [{
"Subject": "Howdy their"
}, {
"Subject": "Howdy there"
}, {
"Subject": "Howdy they're"
}]
}
var obj = json.Tasks;
for (var i = 0; i < obj.length; i++) {
activitySub = (obj[i].Subject);
if (activitySub != "Howdy their") {
activities1.push({
activitySub,
})
}
if (activitySub === "Howdy their") {
activities2.push({
activitySub,
})
}
}
console.log(JSON.parse(JSON.stringify(activities1)));
console.log(JSON.parse(JSON.stringify(activities2)));
const html = activities1.map(obj => {
let item = document.querySelector('#template').innerHTML;
item = item.replace('{sub}', obj.activitySub);
return item;
});
document.querySelector('#list').innerHTML = html.join('');
<ul class="list-group">
<li class="active">
<a href="#"> Howdy</a>
</li>
<li>
<a href="#"> Howdee</a>
</li>
</ul>
<ul class="list-group">
<div id="list"></div>
<template id="template">
<h5 class="media-heading">{sub}</h5>
</template>
</ul>
Hm, perhaps I got carried away and made this too complicated, but perhaps this more generic approach helps.
You could start with this markup
And do this in javascript