【发布时间】:2014-11-17 20:02:24
【问题描述】:
我使用 sockte.io 从服务器获取我的数据,并且取决于数据(item.text)我必须更改图像。 我尝试访问 DOM 并使用指令修改图像,但没有成功。
这是我的代码:
HTML:
<table>
<tr ng-repeat="item in items" myDirective>
<td><img ng-src="{{myImages}}" ></td> <td>{{item.text}}</td>
</tr>
</table>
JS:
App.directive('myDirective', function(){
return {
link: function($scope, elm){
console.log('eee', elm);
elm[0]['children'][0]['children'][0].attr('src',"/url/to/the/image");
}
}
});
我该如何解决这个问题,或者是否有更好的方法来解决这个问题。
更新:
在给定时间图像不相同,我想使用它们的索引访问每个图像的索引。
更新: 我添加了这个example,我该如何修改例如具有'text 2'的图像
【问题讨论】:
-
在你的小提琴中只有一个图像地址:
http://www.exlibrisgroup.com/fr/files/Products/question_icon.gif那应该是一个数组吗? -
这不是我的全部代码,我已经更新了示例(只是我添加了一个新图像),我想用这个图像只更新“文本 2”。我该怎么做?
-
这肯定会有所帮助。谢谢
标签: javascript angularjs angularjs-ng-repeat angular-directive