Im trying to save a some values into a variable.
Im iterating over a list and I want to save the object if it is a Description
<#if item[prop].value?starts_with("Description:")>
<#assign description = item[prop].value>
</#if>
Then I try to create a table for this Description Items.
<#if description?length gt 0>
<#list description as desc>
<table class="itemtable" style="width: 100%; margin-top: 0px;">
<tr>
<td><strong>${desc?replace('&', '&')?replace('\n', '<br/>')}</strong></td>
</tr>
</table>
</#list>
</#if>
The problem is that I'm only getting the last Description value instead of all the Descriptions.
So it I cannot see the rest of your code but it appears that you are overwriting the value of description for every iteration in the loop.
If you want to iterate over the descriptions after so you can print them you will need a array or json. Something like:
<#assign x = []> <#-- create the array -->
<#assign x = x + [ "popo" ] /> <#-- add to it -->
One thig I would say is that you can really just create the description table WHILE you iterate over the initial list and be done with it?
ps. you may want to put the <#list> element around the tags instead of duplicating the whole table...
** warning: all code was written on the fly and is untested. use the concepts don't copy paste.
Related
I am trying iterate over an array in a JSP using c:forEach. What I want is to convert each array element to lowercase, remove all the white spaces and concatenate '-wrapper' at the end of it. I want to use this value as the id of an div.
For example, if an element in array is 'Mobile Devices', I want the final value to be 'mobiledevices-wrapper'.
I'm not aware if there are such function like replace() and toLower() in JSTL. How can I modify the below code. Please help.
<c:forEach items="${userChargingTypeAccessArray}" var="chargingType">
<div id="${chargingType.value}"></div>
</c:forEach>
You can use fn:replace() and fn:toLowerCase().
<c:forEach items="${userChargingTypeAccessArray}" var="chargingType">
<div id="${fn:toLowerCase(fn:replace(chargingType.value,' ',''))}-wrapper"></div>
</c:forEach>
I want to set chart-data with a name stored in the array but its not working.
I stored array names into an array and assign name to chart-data with ng-repeat but chart-data not taking any names from the array it display none.it shows chart only if name is directly assigned.
<div ng-repeat="x in data123">
<h4>{{x}}</h4>
<canvas tc-chartjs-doughnut chart-options="options1" chart-data=x auto-legend></canvas>
</div>
array is
$scope.data123=['basketballl','Dancee'];
this worked only if
<canvas tc-chartjs-doughnut chart-options="options1" chart-data=Dancee auto-legend></canvas>
how can I assign array value to chart-data
I also tried
chart-data={{x}}
chart-data="x"
none of them working
chart.js initially accepts label and value properties only except colors and all.
you need to change in script which is given by chart.js..
suppose your propery from array is xyz.. you need to craete a segment in script like segment.xyz like this or replace label with your property name
hope it vl helps
chart-data takes only array not array names that stored in array.if you want to use ng-repeat to show multiple graphs insert array for chat-data in another array with other datas.
$scope.data1.push({
value: data.Group[i].Count[j],
color: chartColor[j],
highlight: chartColor[j],
label: data.Group[i].options[j]
});
$scope.groupDet.push({'groupid':data.Group[i].groupID,
'groupName':data.Group[i].groupName ,
'ff':$scope.data1
});
<div ng-repeat="x in groupDet">
<h4>{{x.groupName}}</h4>
<canvas tc-chartjs-doughnut chart-options="options1" chart-data=x.ff auto-legend></canvas>
Hope someone can help me out with this:
I'm working with knockout and have the following json array:
[[174302,"BUSINESS - APPLICATION TO CONDUCT A BUSINESS FROM HOME.pdf",".pdf","DK89639"],[120183,"Glovent-Brochure.pdf",".pdf","DK472894"]]
inside my "consumerData" variable.
As you can see there are 2 arrays with 4 elements inside each.
Here is how I am trying to access it:
<div data-bind="foreach: consumerData" style="margin-bottom:100px;">
<table>
<tr>
<td colspan="2">
<p style="font-size:larger; margin-bottom:5px;"><a data-bind="attr: { href: 'http://someaddress/address/'+consumerData[0]+''+consumerData[2]+'?key='+consumerData[3]+'' }"><div data-bind="text: consumerData[1]"></div></a></p>
</td></tr>
</table>
</div>
So this is looping twice which is correct but how do I access my data inside each array?
PLease help!
Thanks!
Regards
Francois
You can access unnamed data within a loop by accessing the $data object (instead of consumerData again), which represents the current context
See this fiddle:
https://jsfiddle.net/5c6y46bo/
Also, you don't need to put a div inside your link to hold the text of the current object, just put the text binding within the <a> element's binding alongside the attr binding.
I am loading data from database in JSON Format, like this: ($scope.fees):
{"1_0":"2000","1_1":"1900","1_2":"1800","1_3":"1700","1_4":"1600","1_5":"1500","1_6":"1400","1_7":"1300","2_0":"4000","2_1":"3900","2_2":"0","2_3":"0","2_4":"0","2_5":"0","2_6":"0","2_7":"0"}
This needs to be displayed in a table (like grid), in which rows and columns are not fixed. This code works for me now:
<tbody data-ng-repeat="obj in courses"><!-- Courses JSON -->
<tr><th>{{obj.name}}</th></tr>
<tr data-ng-repeat="bat in obj.batches"><!-- Each course contains Batches -->
<td>{{bat.bname}}</td>
<td data-ng-repeat="obj in categories"><!-- Columns based on categories -->
<input type="text" name="{{bat.bid}}_{{obj.id}}" data-ng-model="fees.1_0" />
</td>
</tr>
data-ng-model="fees.1_0" should be actually as provided for the name attribute: data-ng-model="fees.{{bat.bid}}_{{obj.id}}" but this doesn't work. Is there any solution to get this working? Thanks in advance.
Edit: I can change the JSON format if there is a better solution to get this done. The current format is batch<underscore>category: fees
Try data-ng-model="fees[bat.bid + '_' + obj.id]"
Check this Demo. This shows how to attach model dynamically from JSON object.May this will help you.
Just like variable keys in javascript use [] in the ng-model as the as bracket value must be your object key
I am trying to display string array in JSP page.
I have got a test String array in my controller set this to my registration model
String[] test={"ab","cb","sc","ad"};
registration.setTestArray(test);
Now I am trying to display it in jsp Its working fine if I do like this
<tr>
<c:forEach var="arr" items="${registration.testArray}">
<td>${arr} </td>
</c:forEach>
</tr>
But my problem is I want to display only some of the values from this array like 2nd and 4th index of this array.
I tried like
<tr>
<c:forEach var="arr" items="${registration.testArray}">
<td>${arr[2]} </td>
</c:forEach>
</tr>
but its throwing an error. This is just a test in my actual project I have long array of array from which I have to display some selected values.
I am thinking of doing this by first process my required values in controller and then display it in jsp. But I am not sure is this the best method. It would be great help if someone suggest me the better way.
It depends on how you get these "selected values". You can:
${registration.testArray[2]}
you can loop using a specific step of the c:forEach tag
you can loop everything and check <c:if test="${selectedValues.contains(arrItem)}