Problem with cyclizing certain elements in nested descriptors of imported arrays
<div class="sub_container">
<div class="logo-col"> </div>
<h2>Welcome to {{title}}</h2>
<script>
function showDiv() {
var Displayobj = "";
var Finalobj = "";
for (var i = 0; i < "{{projects.length}}"; i++) {
Displayobj="{{projects.[i].[0]}}"+" current value is "+"{{projects.[i].[2]}}";
Finalobj = Finalobj + " ||| "+Displayobj;
}
document.getElementById('contentdiv').innerHTML = Finalobj;
document.getElementById('contentdiv').style.display = "block";
}
</script>
<input type="button" value="Value per Item" id="MyButton" onclick="showDiv()" />
<button type="button">Value per Center</button><button type="button">Amount of projects</button><button type="button">Potential of projects</button>
<div id = "contentdiv" style = "display:none;" class="sub_cnt_col" >
</div>
What I'm trying to do is indicate which elements of the handlebar array
{{projects}}
are displayed based on the button that I click. At the moment, I just completed one button, but " {{projects.[i].[0]}}"
returns nothing. On the webpage I see:
||| current value is ||| current value is ||| current value is
.
But if I enter a number, such as 0 for "i", it works fine, but I need to iterate over all instances.
projects contain such an array ---->
projects=[[Computer,info,50],[Desk, info, 10],[Plane, info, 450]]
EDIT: {{projects [i] [0]}} doesn't work ---> it just loads an empty TextEdit file
EDIT: --- >
<ul class="people_list">
{{#each projects}}
<li>{{this}}</li>
{{/each}}
</ul>
, . AKA: 1- 3- , , handlebars.
: : {{projects[i][0]}} -, : , .
EDIT: {{project[0][0]}} for, , - for, .
EDIT: , for i, for , , - . ,
EDIT: - , , , , , .
: , javascript HTML, chiliNUT. , 1 HTML.
EDIT:
var indexController = {
index:function(req, res){
var data = {
title: "whatever"
};
var exphbs = require('express-handlebars');
var hb = require('handlebars');
// Creates the access token and uses the smartsheetSDK
// specifies which sheet to go into
var options = {
id:
};
var http = require('http');
var rowIds = [];
var dupcities = [];
var cities = [];
var projects = [];
var finrow=0;
var moneyDone = 0;
var sheetRowlength=0;
var ProjectsSortedintoCity=[];
var moneymade=0;
var ProjperCit = 0;
// Gets the specific row
/* jshint loopfunc:true */
smartsheet.sheets.getSheet(options)
.then(function (data0) {
//gets the entire sheet, but only the rowIds are used
for (var i = 0; i <= data0.rows.length-1;i++) {
rowIds.push(data0.rows[i].id);
//pushes/prints the row ids
sheetRowlength =(data0.rows.length);
options= {sheetId:
rowId: data0.rows[i].id};
//sets a new options for the rows
//gets the row
smartsheet.sheets.getRow(options)
.then(function (data1) {
projects.push([]);
for( var b = 0; b < data1.cells.length; b++){
projects[finrow].push(data1.cells[b].value);
//prints out all the values of the row
}
dupcities.push(projects[finrow][4]);
finrow++;
if(projects.length===sheetRowlength){
var cities = dupcities.slice() // slice makes copy of array before sorting it
.sort(function(a,b){
return a > b;
})
.reduce(function(a,b){
if (a.slice(-1)[0] !== b){ a.push(b);}// slice(-1)[0] means last item in array without removing it
return a;
},[]);
for (var z = 0; z <cities.length; z++) {
ProjectsSortedintoCity.push([]);
ProjectsSortedintoCity[moneyDone].push(cities[z]);
for (var x= 0; x <projects.length; x++) {
if(projects[x][4]===ProjectsSortedintoCity[moneyDone][0]){
ProjperCit++;
moneymade=moneymade+projects[x][40]+projects[x][41]+projects[x][42]+projects[x][43];
}
}
ProjectsSortedintoCity[moneyDone].push(moneymade);
ProjectsSortedintoCity[moneyDone].push(ProjperCit);
moneyDone++;
moneymade=0;
ProjperCit=0;
}
data.projects=ProjectsSortedintoCity;
data.cities=cities;
system.loadView(res,'index', data);
}
})
.catch(function (error){
console.log(error);
data.error=true;
system.loadView(res,'index', data);
});
}
console.log("HIIIIELO");
})
.catch(function (error) {
console.log(error);
data.error=true;
system.loadView(res,'index', data);
});
// load index view from views, with passed data
}
};
// add controller functions to exports
module.exports = indexController;
, .
var exphbs = require('express-handlebars');
var hb = require('handlebars');
app.engine('handlebars', exphbs({
layoutsDir: 'yourDir',
defaultLayout: 'main',
partialsDir: ['/views/partials/'],
helpers: {
formatText: function(data) {
var sendData = '';
//your function for formating data
//fill 'sendData' with html how u wanna type it in HTML
return new hb.SafeString(sendData);
}
}
}));
app.set('views', config.root + '/app/views');
app.set('view engine', 'handlebars');
file.hbs ..
{{ formatText projects }}
, .