I have a table where I need to apply two different classes, using expressions.
1st class is applied based on following expression.
{'Up':'class-up', 'Down':'class-down'}[a.status]
and 2nd class is applied based on bold: !a.read
The classes here are class-up, class-down, bold.
So how should be the expression framed? I tried:
<tr ng-repeat="a in all" ng-class="{{'Up':'class-up', 'Down':'class-down'}[a.status],bold: !a.read}">
<tr ng-repeat="a in all" ng-class="{'Up':'class-up', 'Down':'class-down'}[a.status],bold: !a.read">
But I keep getting errors in console. What is the correct format to apply these classes based on the given expressions
With the clarification from your comment:
<tr ng-repeat="a in all" ng-class="{'class-up': a.status=='up', 'class-down': a.status=='down', 'bold': !a.read}">hello world</tr>
Related
I am trying to output a table using handlebars.
Right now it loops through the each row, and then through each column, but how can I grab the data from the row based on {{col.name}}?
See here, I need to get COLUMNNAME from {{col.name}}
{{#rows as |row|}}
<tr>
{{#../cols as |col|}}
<td>{{row.COLUMNNAME}}</td>
{{/../cols}}
</tr>
{{/rows}}
In js this would be like row[index][col.name];
Any idea for solutions?
Found the answer, it's the lookup tag.
{{lookup row col.name}}
is equal to
row[col.name]
I have many text files. In each text file, there is a section of interest (below):
<tr>
<td ><b>发起时间</b></td>
<td colspan="2" style="text-align: left">2015-04-08</td>
<td style="width: 25%;"><b>回报机制</b></td>
<td colspan="2" style="text-align: left">使用者付费</td>
</tr>
The information that varies across files is the date only. In this case, the date is 2015-04-08.
I want to extract the date. I am an R user, and I normally would use str_match from the stringr package. I would indicate the following as the start of the string:
<td ><b>发起时间</b></td>
<td colspan="2" style="text-align: left">
However, I am not sure what to do given that this string is spread over two lines. What can I do? (It also contains Chinese characters, but that's a separate issue)
But I'm not sure how to do so, given that
Doing it with Regex
It's not advisable to use a regex to parse HTML due to all the possible obscure edge cases that can crop up, but it seems that you have some control over the HTML so you should able to avoid many of the edge cases the regex police cry about.
Proposed solution with Regex
Can you use the \s+ where the carriage return and new line would be. The resulting regex would look like this:
<td ><b>发起时间<\/b><\/td>\s+<td colspan="2" style="text-align: left">([0-9]{4}-[0-9]{2}-[0-9]{2})<\/td>
** To see the image better, simply right click the image and select view in new window
And based on your sample text. The first capture group would then contain the string of characters that resembled the date. It should be noted that the regex is not actually validating the date, it's just matching the format.
Explained
The \s+ regex will do the following:
\s matches any white space character
+ allows the preceeding regex to match 1 or more times
Since we know there will be a carriage return, new line, and what appears to be a tab or multiple spaces, then all of those will be matched. However if these whitespace characters are optional in your source files, then you could use the \s*. In this case the * will match zero or more whitespace characters.
Example
Please see this live example
I am writing a phpunit test... on my page I have several rows, one of them is like this:
<tr><td>MATCH<small><span class="glyphicon glyphicon-pushpin"></span></small></td></tr>
Some are like this:
<tr><td>NOT A MATCH 1</td></tr>
<tr><td>NOT A MATCH 2</td></tr>
<tr><td>NOT A MATCH 3</td></tr>
how can I run a test to check that the row with the pushpin glyphicon is the one with "MATCH"?
Basically I want the test to confirm that the glyphicon is appearing on the correct row, and just having something like $crawler->filter('small:contains("' . $glyphCode . '")')->count() only confirms that the glyph exists - not that it's in the right place.
Any help appreciated, thank you.
You can use XPath Selectors with Symfony's DomCrawler.
To select your desired element use this XPath expression:
//td//small/span[#class="glyphicon glyphicon-pushpin"]
Then place it inside a PHPUnit assertion.
$this->assertEquals(1,
$crawler->filterXPath('//td//small/span[#class="glyphicon glyphicon-pushpin"]')->count()
);
I've used assertEquals 1 as expected value, to ensure that one element is found on the page.
Actually, the question can be treated as a string match problem.
There are several different ways to do that.
use PHP Simple HTML DOM Parser
$ret = $html->find('td[class=*glyph]');
use regular expression in PHP
the pattern string may like /class="[^"]+glyph/
run grep command in the shell
$ grep glyph xxx.php
reStructuredText has nice support for option lists. For example, rst2html.py translates this RST markup
Options:
--foo does a foo
-b, --bar ABAR bar something
into the following nicely formatted HTML table:
<dt>Options:</dt>
<dd><table class="first last docutils option-list" frame="void" rules="none">
<col class="option" />
<col class="description" />
<tbody valign="top">
<tr><td class="option-group">
<kbd><span class="option">--foo</span></kbd></td>
<td>does a foo</td></tr>
<tr><td class="option-group">
<kbd><span class="option">-b</span>, <span class="option">--bar <var>ABAR</var></span></kbd></td>
<td>bar something</td></tr>
</tbody>
</table>
</dd>
This doesn't seem to extend naturally to positional arguments, however; for example
Arguments:
foo does a foo
bar ABAR bar something
renders as HTML completely lacking a table structure:
<dt>Arguments:</dt>
<dd>foo does a foo
bar ABAR bar something</dd>
Is there some way to produce an options list table for command line arguments that are not prefixed by dashes or slashes?
Yup. The rather limited syntax of option lists is not very well documented here:
http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#option-lists
Here's the really irritating thing. Say you are writing up a series of options and some of them fit the syntax of an "option" per the preceding link, but some do not. For example --opt==keyword does (and "keyword" will be italicized whether you want it or not), but --pot=BLACK|KETTLE doesn't. Docutils will put all the ones that fit their syntax into a nice option-list <table> template, but where they don't, it drops out of the table format and codes them as standard <dl>s. So right in the middle of your stack of options are a couple that don't look like the others.
I'm using plone and trying to display a form result in a page template.
I'm trying to filter some database results using tal:condition with a python expression but it always evaluates to false.
The code looks like this:
<tr tal:repeat="result view/results">
<td> <span tal:condition="python:view.teams[0]==result.team_id" tal:replace="result/position">Position</span></td>
<td> <span tal:condition="python:view.teams[1]==result.team_id" tal:replace="result/position">Position</span></td>
</tr>
I want the table cells to be filled with the team position when the team id is matched in the result, but the cells always are empty.
If I remove the tal:condition from the span and replace the tal:replace="result/position" with tal:replace=python:view.teams[0]==result.team_id it prints True or False so I can check that the result is correct.
Can anyone help me about this issue? Why does tal:condition allways evaluate false?
I'd fully expect this to work, so something else must be wrong.
Python expressions such as yours are commonplace; there are several examples on the internet to show they do normally work.
Try further debugging the values with tal:replace="python:repr(view.teams)" and tal:replace="python:repr(result.team_id)" statements and similar to be 100% certain of what your data structures look like.