how to iterate over objects id value ? in vue js - arrays

I have a data JSON file locally where I can get the data into a component and print the object value depending on the object array number starting from 0 and on ... how can I print it using the object's id value?
in resolution as an example id=321 I want to print that object.
here is my current working code printing by object array value:
<template>
<div class="exespotbody">
<center><h2> Stories Spotlight </h2></center><br>
<div class="Fgrid">
<!-- single news Block for data-->
<a
v-bind:key="dataList[0].id"
:href="`posts/${dataList[0].id}`"
class="Gmodule"
style="display:flex;text-decoration:none;color:#14a0fd;"
>
<div>
<!-- <img src="https://fintechapp.s3.us-east-2.amazonaws.com/y2qYjf8e2hp8z5yrgyfxF2NN?response-content-disposition=inline%3B%20filename%3D%22BoxLogo.png%22%3B%20filename%2A%3DUTF-8%27%27BoxLogo.png&response-content-type=image%2Fpng&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAJG6DG75G7BXQ3XUA%2F20210115%2Fus-east-2%2Fs3%2Faws4_request&X-Amz-Date=20210115T192217Z&X-Amz-Expires=518400&X-Amz-SignedHeaders=host&X-Amz-Signature=26b742c676a7fc0854c1efa0c81bf60e9239bc5068606262b3b1eab0f7a21245">
-->
<img :src="`{{ dataList[0].logo_url}}`"> </img>
<h6> {{ dataList[0].title }} </h6>
<!-- <p v-html="dataList[0].blog_entry"> </p> -->
<hr>
<p> {{ dataList[0].author.name }} </p>
<p> {{ dataList[0].author.title}} </p>
</div>
</a>
<!-- single news Block for data END-->
</div>
</div>
</template>
<script>
import dataData from "#/data/data.json";
export default {
name: 'StoriesSpotlight',
data() {
return {
dataList: dataData,
}
}
}
</script>
the result on screen :
Here is a is Vue tools pic for data:
what I want to do is print the data of the object bind by the id of the object for example id=321 that would be my next step...

So you want to find an object by its id from an array, then you can use find() on dataList
dataList.find(item => item.id === 321).title
dataList.find(item => item.id === 321).author.name
dataList.find(item => item.id === 321).author.title

I might be misreading this question, but I think you're talking about using object properties?
If so, just copy the lines used for displaying the other object properties
<img :src="`{{ dataList[0].logo_url}}`"> </img>
<h6> {{ dataList[0].title }} </h6>
<h6> ID: {{ dataList[0].id }} </h6>
<!-- <p v-html="dataList[0].blog_entry"> </p> -->
<hr>
<p> {{ dataList[0].author.name }} </p>
<p> {{ dataList[0].author.title}} </p>
For iterating across the full dataList Use v-for
<div v-for="entry in dataList" key="entry.id" class="Fgrid">
<!-- single news Block for data-->
<a
v-bind:key="entry.id"
:href="`posts/${entry.id}`"
class="Gmodule"
style="display:flex;text-decoration:none;color:#14a0fd;"
>
<div>
<!-- <img src="https://fintechapp.s3.us-east-2.amazonaws.com/y2qYjf8e2hp8z5yrgyfxF2NN?response-content-disposition=inline%3B%20filename%3D%22BoxLogo.png%22%3B%20filename%2A%3DUTF-8%27%27BoxLogo.png&response-content-type=image%2Fpng&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAJG6DG75G7BXQ3XUA%2F20210115%2Fus-east-2%2Fs3%2Faws4_request&X-Amz-Date=20210115T192217Z&X-Amz-Expires=518400&X-Amz-SignedHeaders=host&X-Amz-Signature=26b742c676a7fc0854c1efa0c81bf60e9239bc5068606262b3b1eab0f7a21245">
-->
<img :src="`{{ entry.logo_url}}`"> </img>
<h6> {{ entry.title }} </h6>
<!-- <p v-html="entry.blog_entry"> </p> -->
<hr>
<p> {{ entry.author.name }} </p>
<p> {{ entry.author.title}} </p>
</div>
</a>
<!-- single news Block for data END-->
</div>

Related

Hugo - How to display an image in related content

I'm trying to display up to three related articles at the bottom of a blog post using Hugo.
I have some test code where I get data for front matter fields like Title and Summary, but I can't access Image.
Not sure what I am doing wrong
{{ $related := .Site.RegularPages.Related . | first 3 }}
{{ with $related }}
<div class="related-content">
<h2>Related content</h2>
<ul class="article-gallery">
{{ range . }}
<li>
<div class="card">
<a class="button" href="{{ .RelPermalink }}">
<img src="" alt ="">
</a>
<div>
<h3>{{ .Title }}</h3>
</div>
<pre>
{{.RelPermalink}}
{{.Title}}
{{.Summary}}
{{.}}
{{.ReadingTime}}
</pre>
<!-- Cannot Access Image -->
<pre>
{{.Image}}
</pre>
</div>
</li>
{{ end }}
</ul>
</div>
{{ end }}
Custom, user-defined data elements in a page's front matter needs to be accessed through .Params:
{{ .Params.Image }}
See The Hugo Docs
Note: there is a predfined "images" (with an 's') that can be accessed directly. Did you mean to use that instead?

AngularJS - ng-repeat, when it ends, there should be a message saying 'no more products'

I have some products displayed with ng-repeat and paginated. I want someone who can help me with ng-if - to say when ng-repeat finishes or there are no more products when the pagination is over. this is like a carousal previous-next (in one page, four products will be there
<span ng-if='curPage >= category.data.length'>
<center><p class="no-products"> There are no more products to show </p> </center>
</span>
<div class = "col col-25" ng-repeat="product in category.data| pagination: curPage * pageSize | limitTo: pageSize">
<a href="#/tab/details?product_id={{product.id}}"><img class="full-image" src="{{product.link}}">
</a>
<center> <p class="productnamei">
<strong> {{product.name}}</strong> </p>
<a ng-href="#/tab/details?product_id={{product.id}}" class="button button-small button-calm">
Buy Now
</a>
</div>
you can check it with $last ($last boolean true if the repeated element is last in the iterator.)
Example
<body ng-app="app">
<div ng-repeat ="item in [1,2,3]" tooltip>
<span data-toggle="tooltip" ng-bind="item"></span>
<div ng-if="$last">Completed</div>
</div>
</body>

Angular search not filtering properly

I have a list of JSON data that I need to be able to filter by typing a name in. The results should then only display those listings which have that name in the result. It is currently just hiding the other names, and still showing all of the other listings.
How can I set the filter so that when you type in an actors name, it only shows the movie listings that actor is listed in?
This is the markup used to display the listings, as well as the Angular filter code:
<div class="row" ng-repeat="movies in results | filter:genre">
<div class="col-lg-12">
<div class="well well-sm">
<div class="row">
<div class="col-xs-3 col-md-3 text-center">
<img src="" alt="poster"
class="img-rounded img-responsive" />
</div>
<div class="col-xs-9 col-md-9 section-box">
<h2>
{{movies.Name}}
</h2>
<div class="row rating-desc">
<div class="col-md-12">
<span class="glyphicon glyphicon-time"></span>{{movies.Duration}}<span class="separator">|</span>
<span class="glyphicon glyphicon-signal"></span>{{movies.Rank}}<span class="separator">|</span>
<a class="bookMovie" href="http://www.fandango.com/{{movies.Name}}">Book Now!</a>
</div>
</div>
<hr>
<p>
{{movies.Description}}
</p>
<p ng-repeat="actor in movies.Actors | filter:actor" >
<span ng-bind="actor"></span>
</p>
<hr />
</div>
</div>
</div>
</div>
</div>
The JSON and rest of the code can be seen in this plunker:
https://plnkr.co/edit/ZmxaSRg9ir0qlNNtOyCd?p=preview
You can filter by object like this filter:{ Genres: genre, Actors: actor }
<div class="row" ng-repeat="movies in results | filter:{ Genres: genre, Actors: actor }">
plnkr link
Thats because you should put the actor filter in your parent ng-repeat, check below plnkr:
https://plnkr.co/edit/k1JVXL0Cpxysjhn2tNx7?p=preview
<div class="row" ng-repeat="movies in results | filter:actor | filter:genre">

how can hide and show li tag in angularjs?

I'm using angularjs 1.4.8. I'm trying to hide & show operation in <li>.
My code is given below:
<ul class="bk_crs_rslt">
<li ng-repeat="c in courses">
<h4>
<a href="#" ng-click="show = !show"> {{c.CourseName }}
<img src="image/bk_ad_btn.jpg" />
</a>
</h4>
<p><span style="color:#337ab7;">{{c.CollegeName}}</span><br>{{c.CountryName}}</p>
<p ng-show="show">
<b>Tution Fee</b> : {{c.Fee}}<br>
<b>Level</b> : {{c.LevelName}}<br>
<b>Detail </b> : {{c.Detail}} <br>
<b>Duration </b> : {{c.Duration}}<br>
<b>Subject </b> : {{c.Subjec}}t<br>
<b>IELTS Score </b> : {{c.Score}}<br />
</p>
</li>
</ul>
How can hide & show in <li> tag?
plunker given here
https://plnkr.co/edit/lsIypaBviXNvEi7Pwok4?p=info
its working in plunker but not working my solution?
Try to use show as property
Like this
<ul class="bk_crs_rslt">
<li ng-repeat="c in courses" >
<h4> {{c.CourseName }}<img src="image/bk_ad_btn.jpg" /> </h4>
<p ng-show="c.show"><span style="color:#337ab7;">{{c.CollegeName}}</span>
<br>{{c.CountryName}}</p>
</li>
</ul>

AngularJS - ng-repeat data flashes then dissapears

I have the following:
<li ng-repeat="deposit in currentDeposits">
<img src="#{{ deposit.displayUrl }}" />
<a class="name" href="http://steamcommunity.com/profiles/#{{ deposit.steam_id }}">#{{ deposit.displayName }}</a>
<p class="name">Deposited #{{ deposit.items.length }} skins worth $#{{ deposit.value }}!</p>
<hr />
<li ng-repeat-end>
<div class="new-round">
<p>^ NEW ROUND START ^</p>
</div>
<hr />
</li>
</li>
<li ng-repeat="deposit in lastGameDeposits">
<img src="#{{ deposit.displayUrl }}" />
<a class="name" href="http://steamcommunity.com/profiles/#{{ deposit.steam_id }}">#{{ deposit.displayName }}</a>
<p class="name">Deposited #{{ deposit.items.length }} skins worth $#{{ deposit.value }}!</p>
<hr />
<li ng-repeat-end>
<div class="new-round">
<p>^ NEW ROUND START ^</p>
</div>
<hr />
</li>
</li>
This first ng-repeat data shows fine, however the data inside the second ng-repeat only flashes on screen, then disappears. Occasionally the data will stay however this isn't common.
Is this a know issue?

Resources