简体   繁体   English

如何从json响应中获取第一张图片

[英]How to get first image from json response

How to get first image form the response from below response如何从下面的响应中获取第一张图片

["147038089457a43b5e47d2a_job1.jpg", "147038089457a43b5e48065_job2.jpg", "147038089457a43b5e4829c_jobo_3.jpg"]

I have tried ng-repeat is not working here.我试过 ng-repeat 在这里不起作用。

What you have mentioned in your question is an array.您在问题中提到的是一个数组。

 ["147038089457a43b5e47d2a_job1.jpg",
 "147038089457a43b5e48065_job2.jpg",
 "147038089457a43b5e4829c_jobo_3.jpg"]

Assuming this value is assigned to say a variable x, getting the first image from this response should be as simple as reading the first value x[0] .假设这个值被分配给一个变量 x,从这个响应中获取第一个图像应该和读取第一个值x[0]一样简单。

<img src="x[0]" />

in you controller you would have...在你的控制器中,你会有......

$scope.amitImages = ["147038089457a43b5e47d2a_job1.jpg",
"147038089457a43b5e48065_job2.jpg",
"147038089457a43b5e4829c_jobo_3.jpg"]

If you want to do a repeat: In your view (html) you would have..如果你想重复一遍:在你看来(html)你会有..

<ul>
    <li ng-repeat="image in amitImages">
      <img ng-src="{{ image }}"/>
    </li>
  </ul>

If you JUST want the first image: In your view (html) you would have..如果您只想要第一张图片:在您的视图 (html) 中,您将拥有..

<img ng-src="{{ image[0] }}"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM