Duplicate display Issue in an AngularJS drop-down list - json
look this image to see the problem
I develop a simple application (to start) in AngularJS and I have a worry because my drop down list that allows to choose the list of movies by style, displays the styles present several times in my JSON file. I have tried several solutions but nothing works and I block on it for a while, there is only that (and can be added by after) to finish my application and fill my JSON file.
JSON FILE :
[
{
"picture" : "la-malediction",
"title" : "LA MALEDICTION",
"year" : "1976",
"time" : "1h41",
"director" : "Richard Donner",
"synopsis" : "Robert Thorn est ambassadeur des États-Unis à Londres. Plusieurs décès tragiques et étranges ont lieu dans son entourage. Keith Jennings, un photographe et le père Brennan finissent par convaincre Thorn que Damien, son fils de cinq ans, un orphelin aux origines obscures qu'il a adopté à sa naissance à l'insu de sa femme qui venait de faire une fausse couche, n'est autre que l'Antéchrist.",
"style" : "Horreur",
"scenario" : "David Seltzer",
"production" : "20th Century Fox",
"music" : "Jerry Goldsmith",
"score" : "7.5/10",
"actors" : "Gregory Peck, Lee Remick, David Warner, Billie Whitelaw, Patrick Throughton, Harvey Stephens, Sheila Reynor, Martin Benson, Leo McKern, Tommy Duggan, Anthony Nicholls, Nicholas Campbell"
},
{
"picture" : "volte-face",
"title" : "Volte/Face",
"year" : "1997",
"time" : "2h18",
"director" : "John Woo",
"synopsis" : "1991 : le terroriste Castor Troy tente d'abattre son ennemi juré Sean Archer, agent du FBI. Au moment du tir, il rate Archer, mais abat accidentellement son fils. Six ans plus tard, Castor est repéré à Los Angeles. À la suite d'un violent affrontement à l'aéroport, Castor est plongé dans le coma par Archer. Ce dernier apprend que Troy a placé une bombe chimique en ville. Il prend le visage de Troy, grâce à une opération chirurgicale, afin d'infiltrer un pénitencier secret où est détenu Pollux, le frère de Castor, pour connaitre l'emplacement de la bombe. Entre-temps, Troy sort du coma et se fait lui-même greffer le masque d'Archer, puis tue tous ceux qui sont au courant de l'opération, volant ainsi le travail, la vie et la femme d'Archer. Livré à lui-même, privé de son identité, ce dernier décide de s'évader...",
"style" : "Thriller",
"scenario" : "Mike Werb, Michael Colleary",
"production" : "Paramount Picture",
"music" : "John Powell",
"score" : "9/10",
"actors" : "Joh Travolta, Nicolas Cage, Joan Allen, Alessandro Nivola, Dominique Swain, Gina Gershon, Nick Cassavetes"
},
{
"picture" : "la-fureur-du-dragon",
"title" : "La fureur du dragon",
"year" : "1997",
"time" : "2h18",
"director" : "John Woo",
"synopsis" : "1991 : le terroriste Castor Troy tente d'abattre son ennemi juré Sean Archer, agent du FBI. Au moment du tir, il rate Archer, mais abat accidentellement son fils. Six ans plus tard, Castor est repéré à Los Angeles. À la suite d'un violent affrontement à l'aéroport, Castor est plongé dans le coma par Archer. Ce dernier apprend que Troy a placé une bombe chimique en ville. Il prend le visage de Troy, grâce à une opération chirurgicale, afin d'infiltrer un pénitencier secret où est détenu Pollux, le frère de Castor, pour connaitre l'emplacement de la bombe. Entre-temps, Troy sort du coma et se fait lui-même greffer le masque d'Archer, puis tue tous ceux qui sont au courant de l'opération, volant ainsi le travail, la vie et la femme d'Archer. Livré à lui-même, privé de son identité, ce dernier décide de s'évader...",
"style" : "Kung-fu",
"scenario" : "Mike Werb, Michael Colleary",
"production" : "Paramount Picture",
"music" : "John Powell",
"score" : "9/10",
"actors" : "John Travolta, Nicolas Cage, Joan Allen, Alessandro Nivola, Dominique Swain, Gina Gershon, Nick Cassavetes"
},
{
"picture" : "la-fureur-du-dragon",
"title" : "La fureur du dragon",
"year" : "1997",
"time" : "2h18",
"director" : "John Woo",
"synopsis" : "1991 : le terroriste Castor Troy tente d'abattre son ennemi juré Sean Archer, agent du FBI. Au moment du tir, il rate Archer, mais abat accidentellement son fils. Six ans plus tard, Castor est repéré à Los Angeles. À la suite d'un violent affrontement à l'aéroport, Castor est plongé dans le coma par Archer. Ce dernier apprend que Troy a placé une bombe chimique en ville. Il prend le visage de Troy, grâce à une opération chirurgicale, afin d'infiltrer un pénitencier secret où est détenu Pollux, le frère de Castor, pour connaitre l'emplacement de la bombe. Entre-temps, Troy sort du coma et se fait lui-même greffer le masque d'Archer, puis tue tous ceux qui sont au courant de l'opération, volant ainsi le travail, la vie et la femme d'Archer. Livré à lui-même, privé de son identité, ce dernier décide de s'évader...",
"style" : "Kung-fu",
"scenario" : "Mike Werb, Michael Colleary",
"production" : "Paramount Picture",
"music" : "John Powell",
"score" : "9/10",
"actors" : "John Travolta, Nicolas Cage, Joan Allen, Alessandro Nivola, Dominique Swain, Gina Gershon, Nick Cassavetes"
}
]
<div class="jumbotron">
<input type="text" ng-model="query"/>
<br>
<br>
<select ng-model="styles" ng-options="media.style for media in medias track by media.style"></select>
<div class="order">
<p>
<label><input type="radio" ng-model="direction" /> Croissant</label>
</p>
<p>
<label><input type="radio" ng-model="direction" value="reverse" /> Décroissant</label>
</p>
</div>
</div>
<article class="media" ng-repeat="media in medias | filter : styles">
<div class="jumbotron">
<div class="media">
<h2 id="title-movie">{{media.title}}</h2>
<div class="media-left" >
<img ng-src="images/{{media.picture}}.png" alt="{{media.title}}" />
</div>
<div class="media-body" style="margin-top:15px;">
<p class="description">Style : {{media.style}}</p>
<p class="description">Année : {{media.year}}</p>
<p class="description">Durée : {{media.time}}</p>
<p id="infos"><a class="link-info" href="#/detail/{{medias.indexOf(media)}}">Plus d'info</a></p>
</div>
</div>
</div>
controller ANGULAR JS
Now I got your problem. Well, you can use the Angular UI filter called unique.
I couldn't find the original code, but I found this fork.
So, you just need to add the filter:
var mediaControllers = angular.module('mediaControllers', []);
/**
* Filters out all duplicate items from an array by checking the specified key
* #param [key] {string} the name of the attribute of each object to compare for uniqueness
if the key is empty, the entire object will be compared
if the key === false then no filtering will be performed
* #return {array}
*/
mediaControllers.filter('unique', function () {
return function (items, filterOn) {
if (filterOn === false) {
return items;
}
if ((filterOn || angular.isUndefined(filterOn)) && angular.isArray(items)) {
var hashCheck = {}, newItems = [];
var extractValueToCompare = function (item) {
if (angular.isObject(item) && angular.isString(filterOn)) {
return item[filterOn];
} else {
return item;
}
};
angular.forEach(items, function (item) {
var valueToCheck, isDuplicate = false;
for (var i = 0; i < newItems.length; i++) {
if (angular.equals(extractValueToCompare(newItems[i]), extractValueToCompare(item))) {
isDuplicate = true;
break;
}
}
if (!isDuplicate) {
newItems.push(item);
}
});
items = newItems;
}
return items;
};
});
And then, you put the filter on your ng-options:
<select ng-model="styles" ng-options="media.style for media in medias | unique: 'style'"></select>
I tested it and it's working. I hope it solves your problem.
UPDATE:
You should also update the filter to match the selected item style instead the selected object.
<article class="media" ng-repeat="media in medias | filter : styles.style">
Related
Remove space inside cell (padding)
I already use border-spacing, border-collapse, padding to reduce the space, but it doesn't reduce the space as much as I wanted to. Can we reduce more than this? before added border spacing : after added border spacing etc:
no se como tengas colocadas las etiquetas, pero si los elementos que estan dentro de la celda estan contenidas dentro de un div podrias añadirle a la clase propiedad tipo asi : div class="row-12" dado que al igual que el column el ancho max es de 12
Microsoft translator changing phrase where there are html spans
Plain english sentence is: While in 5th direct and ready for the downshift to 4th overdrive, push the range preselection lever down. Converts to French correctly as: Alors que dans le 5ème direct et prêt pour le downshift à la 4ème overdrive, pousser le levier de présélection de gamme vers le bas. However, when including html (&textType=html), the phrase doesn't have the same meaning: While in 5th direct and ready for the downshift to <span data-id="xyz123">4th overdrive</span>, push the range preselection lever down. Translates to: Alors que dans le 5ème direct et prêt pour le downshift à 4e overdrive, pousser la gamme levier de présélection duvet.
The tags are considered an additional token in the sentence. Similar effect as punctuation, both having an effect on the translation.
When a image is right aligned, text of below paragraphs is not wrapping around Image in html page. But wraps inside the Text area of CKeditor [duplicate]
This question already has answers here: How to wrap text inside to different paragraphs around image inside the first paragraph (<p> tag). (Content is inputted using CKeditor Plugin) (5 answers) Closed 4 years ago. I am using CKeditor to input RichText. Inside the text area of CKEditor, the text is perfectly wrapped over the image. But the text is not wraping on the html page. This is how it looks in CKeditor But my html looks like this. What may be I am missing here. ? Here is the actual code snippet <p>Enter each item on a new line, choose the amount of groups unders settings, and click the button to generate your randomized list. Don't like the first team? Just click again until you do.Fairly pick teams without bias. No need to draw names out of a hat. No need to do a grade school style draft or put hours of thought into the most balanced teams. The most fair dividing method possible is random.Enter each item on a new line, choose the amount of groups unders settings, and click the button to generate your randomized list. Don't like the first team? Just click again until you do.Fairly pick teams without bias. No need to draw names out of a hat. No need to do a grade school style draft or put hours of thought into the most balanced teams. The most fair dividing method possible is random.Enter each item on a new line, choose the amount of groups under <img alt="" src="/media/uploads/2018/09/27/sufs5o_fWCbPPM.jpg" style="float:right; height:1080px; width:420px"> Enter each item on a new line, choose the amount of groups unders settings, and click the button to generate your randomized list. Don't like the first team? Just click again until you do.Fairly pick teams without bias. No need to draw names out of a hat. No need to do a grade school style draft or put hours of thought into the most balanced teams. The most fair dividing method possible is random.Enter each item on a new line, choose the amount of groups unders settings, and click the button to generate your randomized list. Don't like the first team? Just click again until you do.Fairly pick teams without bias. No need to draw names out of a hat. No need to do a grade school style draft or put hours of thought into the most balanced teams. The most fair dividing method possible is random.Enter each item on a new line, choose the amount of groups unders settings, and click the button to generate your randomized list. . </p> <p>s settings, and click the button to generate your randomized list. Don't like the first team? Just click again until you do.Fairly pick teams without bias. No need to draw names out of a hat. No need to do a grade school style draft or put hours of thought into the most balanced teams. The most fair dividing method possible is random.Enter each item on a new line, choose the amount of groups unders settings, and click the button to generate your randomized list. Don't like the first team? Just click again until you do.Fairly pick teams without bias. No need to draw names out of a hat. No need to do a grade school style draft or put hours of thought into the most balanced teams. The most fair dividing method possible is random.Enter each item on a new line, choose the amount of groups unders settings, and click the button to generate your randomized list. Don't like the first team? Just click again until you do.Fairly pick teams without bias. No need to draw names out of a hat. No need to do a grade school style draft or put hours of thought into the most balanced teams. The most fair dividing method possible is random.</p>
<img align="right" hspace="3px" vspace="3px" alt="" src="/media/uploads/2018/09/27/sufs5o_fWCbPPM.jpg" style="height:1080px; width:420px"> Try this on
.floatright { float: right; clear: right; position: relative; margin: 0 0 0.5em 0.5em; } <div style="text-align:justify;margin:6px"> <img src="//upload.wikimedia.org/wikipedia/commons/thumb/c/c7/Mandala1_detail.jpg/150px-Mandala1_detail.jpg" width="150" height="173" class="floatright" > <p> El arte budista tiene su origen en el subcontinente indio (actuales India, Bangladés, Nepal y Pakistán) en los siglos posteriores a la vida de Siddhartha Gautama, el Buda histórico, entre los siglos vi y v a. C. Más tarde, gracias al contacto con otras culturas, logró evolucionar y difundirse por el resto de Asia y el mundo. Una primera etapa, llamada preicónica, se sitúa antes del siglo i d. C. y se caracteriza por no recurrir a representaciones directas de Siddhartha Gautama como el Buda Śākyamuni o de los budas míticos que se suponen existieron en eras pasadas. La etapa siguiente, icónica, tiene por el contrario a la imagen humana del Buda y los budas del pasado, del futuro y de otros universos como símbolo central de sus obras de arte. Desde entonces, el arte budista se diversificó y evolucionó para adaptarse a las nuevas regiones en las que comenzaba a sumar adeptos. Se expandió hacia el este y el norte a través de Asia Central, para formar lo que luego fue clasificado como arte budista del norte —en contraposición al arte budista del sur, que surgiría en el sudeste de Asia. En India, el arte budista floreció e incluso llegó a influir en el desarrollo del arte hindú, hasta que el budismo casi desapareció alrededor del siglo x, con la expansión del hinduismo y el islam. </p> <p> El arte budista tiene su origen en el subcontinente indio (actuales India, Bangladés, Nepal y Pakistán) en los siglos posteriores a la vida de Siddhartha Gautama, el Buda histórico, entre los siglos vi y v a. C. Más tarde, gracias al contacto con otras culturas, logró evolucionar y difundirse por el resto de Asia y el mundo. Una primera etapa, llamada preicónica, se sitúa antes del siglo i d. C. y se caracteriza por no recurrir a representaciones directas de Siddhartha Gautama como el Buda Śākyamuni o de los budas míticos que se suponen existieron en eras pasadas. La etapa siguiente, icónica, tiene por el contrario a la imagen humana del Buda y los budas del pasado, del futuro y de otros universos como símbolo central de sus obras de arte. Desde entonces, el arte budista se diversificó y evolucionó para adaptarse a las nuevas regiones en las que comenzaba a sumar adeptos. Se expandió hacia el este y el norte a través de Asia Central, para formar lo que luego fue clasificado como arte budista del norte —en contraposición al arte budista del sur, que surgiría en el sudeste de Asia. En India, el arte budista floreció e incluso llegó a influir en el desarrollo del arte hindú, hasta que el budismo casi desapareció alrededor del siglo x, con la expansión del hinduismo y el islam. </p> </div>
Iframe with youtube video embed don't appear in ionic2+
I have a request in my web api that give me a Json like this { "$id": "1", "ID": 9710, "post_author": 2, "post_date": "31/08/2017", "post_content": "Assim como aconteceu no primeiro Destiny, a <strong>Bungie</strong> e a <strong>Activision</strong> lançaram nesta quinta-feira (31) um trailer live action de <strong>Destiny 2</strong>, com direito a <strong>Cayde-6</strong> fazendo um discurso motivacional, lembrando que todas as coisas que você ama na Terra se foram (inclusive os cachorrinhos).<br><br><div class=\"video\"><iframe src='https://www.youtube.com/embed/UhE6B3MPsUM'></iframe></div><br><br>O trailer por <strong>Jordan Vogt-Roberts</strong> mais conhecido pelo seu trabalho em <strong>Kong: A ilha da Caveira</strong>.<br><br>A nossa aventura em Destiny 2 começa com os <strong>Guardiões</strong> buscando vingança após ter a última cidade segura na Terra destruída pela Legião Vermelha, liderada pelo poderoso <strong>Ghaul</strong>. Com isso, será necessário que exploremos novos mundos do sistema solar, em busca de armas e habilidades para vencer essa guerra e recuperar a nossa luz.<br><br><strong>Destiny 2</strong> será lançado em 6 de setembro pra <strong>Xbox One </strong>e <strong>PS4</strong>. No PC o jogo será lançado um mês depois no dia 24 de outubro.<br><br><strong>Saiba mais sobre Destiny 2</strong>", "post_title": "Destiny 2 ganha trailer live action ao som Sabotage", "post_name": "destiny-2-ganha-trailer-live-action-ao-som-sabotage", "guid": "http://nextseason.com.br/?p=9710", "meta_value": 9711, "id_post_img": 9711, "link_imagem": "http://nextseason.com.br/wp-content/uploads/live-action-destiny-2.jpg", "id_post_categoria": 9710, "category": "Games" } and in app using Ionic 2 i put the code <div [innerHtml]="post.post_content"> </div> where post.post_content is the post_content from my request. inside the post_content has an with a embed youtube video, but when i run the, the video does not show. In debug appears like that. <div>Assim como aconteceu no primeiro Destiny, a <strong>Bungie</strong> e a <strong>Activision</strong> lançaram nesta quinta-feira (31) um trailer live action de <strong>Destiny 2</strong>, com direito a <strong>Cayde-6</strong> fazendo um discurso motivacional, lembrando que todas as coisas que você ama na Terra se foram (inclusive os cachorrinhos).<br><br><div class="video"></div><br><br>O trailer por <strong>Jordan Vogt-Roberts</strong> the div element always shows empty. Someone can help me? have any idea why this occurs? Sorry my english!
Loop incrementation for url
I want to insert dynamic url from my title, it works but it displays 6*6 'cause of 2 differents loops... I don't know how to do differently... I tried to use global variable but it's the same... (I have 6 Recipes) Thanks ! Code XML : <recette id="r1"> <titre>Cake au chocolat</titre> <cat>dessert</cat> <type/> <nombre>6</nombre> <listeingredients> <ingredient q="150" u="g">chocolat pâtissier</ingredient> <ingredient q="3" u="pièce">oeufs</ingredient> <ingredient q="100" u="g">sucre en poudre</ingredient> <ingredient q="60" u="g">farine</ingredient> <ingredient q="1" u="cuillère à café">levure</ingredient> <ingredient q="80" u="g">beurre</ingredient> <ingredient q="50" u="g">poudre d'amandes</ingredient> </listeingredients> <cuisson> <temps type="preparation">15</temps> <temps type="cuisson">30</temps> <temperature u="C">180</temperature> </cuisson> </recette> <recette id="r2"> <titre>Brownies aux noix de pécan</titre> <cat>dessert</cat> <type/> <nombre>6</nombre> <listeingredients> <ingredient q="200" u="g">chocolat à cuire</ingredient> <cuisson> <temps type="preparation">10</temps> <temps type="cuisson">25</temps> <temperature u="C">180</temperature> </cuisson> <instruction> <etape>Faire fondre le chocolat avec le beurre, soit au bain-marie à feu doux, soit au micro-ondes sur programme 'décongélation'.</etape> <etape>Quand c'est bien fondu, mélanger et ajouter le sucre, les oeufs un par un, la farine, puis les noix de pécan hachées grossièrement.</etape> <etape>Bien mélanger et verser dans un moule carré de 20 cm (ou rectangulaire pas trop grand), chemisé de papier sulfurisé.</etape> <etape>Mettre au four préchauffé à 180°C pendant 25 min.</etape> <etape>Laisser refroidir et couper en carrés.</etape> </instruction> </recette> </listerecettes> Code xq : { for $titre in db:open("recettes")//recette//titre, $j in (6,2,1,5,4,3) order by $titre return <a href="http://127.0.0.1:8984/rest/recettes?query=//recette[#id='r{$j}']"> <ul> <li> { $titre } </li> </ul> </a> } </body> </html>
After your comment I still don't really know what you want to achieve with $j as it is not useful at all and can simply be removed. So I guess you maybe want something else and not just a simple list ordered by thte title - If so, please clearify what you want to achieve. Otherwise, simply removing the $j and using the id attribute will work fine. for $recette in db:open("recettes")//recette let $titre := $recette/titre order by $titre return <a href="http://127.0.0.1:8984/rest/recettes?query=//recette[#id='{$recette/#id}']"> <ul> <li> { $titre } </li> </ul> </a>
Thank you but I had just found an other way ! : for $titre in db:open("recettes")//recette//titre order by $titre return <a href="http://127.0.0.1:8984/rest/recettes?query=//recette[#id='{$titre/..//#id}']"> <ul> <li> { $titre } </li> </ul> </a> I tested your code and it's correct but you've forget "$titre" after order by !