lundi 9 mars 2015

set SVG fill based on database info

My setup is Node, Sails.JS, EJS, and MongoDB.


I'm generating an SVG image based on database values. I am trying to set the FILL color based on whether the DB object has ACTIVE set to true or false. I'm sure I'm missing or doing something wrong. Any help would be greatly appreciated.



<div class="container">
<!--Generic SVG head-->
<svg
version="1.1"
xmlns="http://ift.tt/nvqhV5"
xmlns:xlink="http://ift.tt/PGV9lw"
x="0px"
y="0px"
viewBox="0 0 400 400"
enable-background="new 0 0 400 400"
xml:space="preserve">

<!--Alert function to test Onclick-->
<script>
function bench(bNum) {
alert(bNum);
}
</script>

<!--Run for each bench entry in DB-->
<% _.each(benches, function(bench) { %>
<script>

//Set bFill to 0
var bFill = '0';

//Check if active is set to true in DB
if bench.active == 'true' {
console.log('true')

//Set bFill variable to to green
bFill = '#008000';
} else {
console.log('false');

//Set bFill variable to Grey
bFill = '#C0C0C0';
}
</script>
<!--Fill in RECT info from DB fields-->
<g id="<%= bench.number %>">
<title>Bench:
<%= bench.number %>
</title>
<rect
id="<%= bench.number%>"
x="<%= bench.x %>"
y="<%= bench.y %>"

fill="<%= this.bFill %>"

stroke="#000000"
stroke-width="0.25"
stroke-miterlimit="10"
width="<%= bench.w %>"
height="<%= bench.h %>"
onclick="bench(this.id)" />
</g>
<% }) %>
</svg>

Aucun commentaire:

Enregistrer un commentaire