I have a request that I'm scratching my head over, and I'm hoping someone can help me out. The client is looking for a sidebar widget that would display related items of a product. To conserve on vertical space, I have made this area collapsable using a Bootstrap accordion.
After reviewing what I developed, they like the idea but they wish to take it a step farther. The client would like the first three related items always displayed in this related items area, BUT if the items exceed 3, then add the collapsible element below with a toggle button (SHOW MORE). Problem is, I'm stuck on how the logic would play out in JSTL.
JSTL:
<ul>
<c:set var="count" value="0" scope="page" />
<c:forEach var="itemID" items="${sellableGood.relatediItem}">
<c:set var="count" value="${count + 1}" scope="page" />
<script>console.log(${count});</script>
<li>
${itemID}
</li>
</c:forEach>
</ul>
Here's what I have currently, it's a basic forEach loop that just iterates through all of the related items. I'm puzzled on how I would use the COUNT variable to know when there was more than 3, then put those in a div within this unordered list. Or is there a way to get the total count before I start outputting the unordered list in the first place?
Thank you in advance.
The following snippet should help to check if count is greater than 3
<c:if test="${count > 3}">
your logic
</c:if>
Related
I am trying to make a nice display of my array data within an element that has a certain width/height. What I want to do is that when my data reaches the bottom of the element to start a new column and continue with printing the data within that next column and so on/forth
Any help is much appreciated!
My code:
<div class="repeater" ng-repeat="files in files"> {{files.name}}
<div class='progress-bar'>
<div class='percentage' ng-style="style">
</div>
</div>
</div>
Current view:
HTML/CSS solution
This should be better solved by CSS than by your application logic. You could display the file names as list and adapt the approach at
How to display an unordered list in two columns?
to display them in multiple columns.
For example, I have a dom-repeat like this:
<template is="dom-repeat" id="rows" items="[[rows]]" as="row">
<tr class="result-tb-row" closed$=[[row.closed]]>
<td class="result-tb-data">
<ul class="violation-list">
<template id="rowItem" is="dom-repeat" items="[[row.items]]">
<li on-click="click">[[item]]</li>
</template>
<ul>
</td>
</tr>
</template>
If I want to know which row I am clicking on, I can write a something like this:
this.$.rows.itemForElement(event.target);
However, what if I want to get the exact item corresponding to li I clicked on. How do I do so? I obviously cannot do this.$.rowItem.itemForElement(event.target) because rowItem isn't unique.
Update
event.model.item seems to solve this particular problem. But if you have double nested dom-repeat or more and you want to get the middle layers, you're out of luck. Probably have to implement an iterator yourselves. double nested dom-repeat happens a lot in table. Table is already a nested dom-repeat; if you want a dom-repeat inside a table cell (and you will run into it), double nested dom-repeat happens.
It isn't hard to implement an iterator, just hope that the Polymer team supports more methods for nested dom-repeat because this is an awesome feature.
event.target holds a <li> reference.
When you do this.$.rowItem.itemForElement(event.target), the dom-repeat named rowItem is unique, and it will look what item belongs to that <li>.
But if you just want item data, you can use event.model.item, which holds a reference to the item data that belongs to the line you clicked.
This is a perfectly valid question, I'm facing the same situation. Anyone has a solution?
UPDATE
I found the ID in e.model.__data__. But this feels like a hack
Here it is. It took me a couple of apps to figure this out.
Polymer considers the inner ID to be a dynamically created ID. So using Polymer's automatic node finding for dynamic IDs, you can say:
this.$$('#rowItem').itemForElement(event.target)
As documented here:
https://www.polymer-project.org/1.0/docs/devguide/local-dom.html#node-finding
I'm new to masonry with angular. i have tried to get masonry working with angular up to a certain extend and im facing few issues with it right now. Below given link is what i have done so far and the following are the two issues facing:
<div ng-controller="MainCtrl">
<div class="grid" masonry="true" column-width="460">
<div ng-repeat="item in items" class="item {{item.class}}">
<div><h1>{{item.name}}</h1></div>
<br /> <span>Age: {{item.age}}</span>
<br /> <span>Company: {{item.company}}</span>
</div>
</div>
</div>
Link to jsfiddle for my solution
instance 1
When there is enough space the smaller brick does not get adjusted. E.g. After "Collin Alston" i need to have "Jasmine Rollins" and likewise. How would i accomadate this change? (see for image below as well)
instance 2
Why is it that "style" attribute gets applied to child elements? i need the style to be applied to "item w1 masonry-brick" and not child div's.
I had in instance 1 and changed it to for instance 2 to show the two problems im facing. Hope to get some answers to work my way out. Thank you in advance.
Update 1:
I managed to get masonry working with angular to this extend. Check this out http://jsfiddle.net/h5jfd1wm/38/
But still there are some empty spaces when i resize the window. It's like some bricks from the bottom can fill up those empty spaces. If you can help me out here.
Please see the CodePen below for clarification. I have a situation where I need to order the list dividers based on a "ParentId" field that is in each child of the parent. I have an array of ParentId's which specified the order that the parent items should appear in the list. How might I go about this? If you notice, I am losing the original order of my list dividers when using ng-repeat-start.
See CodePen Here
You need orderBy:
<a class="item"
ng-repeat="item in items | orderBy:'ParentId'">
{{item.Description}}
</a>
http://codepen.io/anon/pen/Ltxfv
I messed with your parent ID's on purpose, so you can see what's happening.
There is ng-repeat and in there are many li's. The superior li's are visible, while the minor ones are not displayed. By clicking on one superior li, the minor should get visible/invisible. All li's are equated in their code, means there is no embedding code which purport who is superior or minor. They are only distinguishable by id. A superior li's has the id 1, while a minor get's the id 1.1.
<li class="list-table" ng-repeat="row in rows" id="{{row.first}}.{{row.second}}" ng-click="toggle_rows(row)")
<div style="list-cell">
<p>{{row.first}}</p>
<p>{{row.second}}</p>
<p>{{row.name}}</p>
<div>
</li>
I tried several things but got stuck. Any advice appreciated! Thanks in advance!