重复不显示图像

时间:2016-10-24 21:22:39

标签: javascript angularjs

import unicodecsv as csv

...

f = open('data.csv', 'wb')
w = csv.writer(f, delimiter = ",")
w.writerow([x.split(',') for x in productList])
f.close()

HTML部分

var name = last_name + ',' + first_name;
if(party=="R")
    party="<img src='/images/r.png'>";
else
    party="<img src='/images/d.png'>";
if(chamber == "senate")
    chamber="<img src='/images/s.svg'>Senate";
else
    chamber="<img src='/images/h.png'>House";
$scope.users.push({
    party_name:party,
    fullname:name,
    chamber_name:chamber,
    district_name:district,
    state_name:state});

当我尝试这样做时,它会打印图像标签而不是图像本身。推送中的其他变量是字符串。字符串部分显示正确。有人可以帮帮我吗??

3 个答案:

答案 0 :(得分:1)

仅使用图像的src作为字符串

var name = last_name + ',' + first_name;
if(party=="R")
    party="/images/r.png";
else
    party="/images/d.png";
if(chamber == "senate")
    chamber="/images/s.svg";
else
    chamber="/images/h.png";
$scope.users.push({
    party_name:party,
    fullname:name,
    chamber_name:chamber,
    district_name:district,
    state_name:state});

然后在html中使用绑定到<img>属性的src

<tr ng-repeat="user in users">
    <td> <img src="{{user.party_name}}" /> </td>
    <td>{{user.fullname}}</td>
    <td> <img src="{{user.chamber_name}}" /> </td>
    <td>{{user.district_name}}</td>
    <td>{{user.state_name}}</td>
</tr>

PLUNKER

答案 1 :(得分:0)

尝试使用类似的东西。

var name = last_name + ',' + first_name
if(party=="R")
    party='/images/r.png';
else
    party='/images/d.png';

if(chamber == "senate")
    chamber='/images/s.svg';
else
    chamber='/images/h.png';

$scope.users.push({
    party_name:party,
    fullname:name,
    chamber_name:chamber,
    district_name:district,
    state_name:state});
enter code here

然后在HTML中分配标记

    <tr ng-repeat="user in users">
        <td>{{user.party_name}}</td>
        <td>{{user.fullname}}</td>
        <td><img src="{{user.chamber_name}}"/> </td>
        <td><img src="{{user.district_name}}"/></td>
        <td>{{user.state_name}}</td>
    </tr>

希望它可以帮到你。

答案 2 :(得分:0)

还记得你应该使用ng-src

<td><img ng-src="{{user.chamber_name}}"/></td>

Angular docs