JavaScript - sort en un array de API SE DESTRUYE

 
Vista:

sort en un array de API SE DESTRUYE

Publicado por eezyzyady (1 intervención) el 14/10/2018 08:47:41
Estoy haciendo una tarea con la API de ghibli pero no consigo ordenarlos con sort, e probado de mil maneras distintas, de ante mano muchas gracias ! les dejo el codigo

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<template>
  <div>
    <h1><a>Lista de Peliculas</a></h1>
    <h3> Ordenar Peliculas por :
      <button @click="sortLowest"> Bajo Rating</button></h3>
      <table>
        <thead>
          <tr>
    <ul>
    <li v-for="film in films" :key="film.title">
      <router-link :to="{name: 'detalle', params: { filmDescription: film.description, filmTitle: film.title, filmDirector: film.director,
      filmProductor: film.producer, filmAnio: film.release_date, filmRT: film.rt_score}}">
 
         {{ film.title }} </router-link> by "{{film.director}}" ({{film.release_date}}) - Rating: {{ film.rt_score}}
    </li>
    </ul>
          </tr>
    </thead>
      </table>
 
 
 
  </div>
 
</template>
 
<script>
 
import axios from 'axios'
 
export default {
 name: 'HelloWorld',
  data () {
    return {
      films: []
    }
  },
  mounted () {
    var comp = this
    var apiUrl = 'https://ghibliapi.herokuapp.com/films'
 
  var promise = axios.get(apiUrl)
            promise.then(function(datos){
   console.log(datos)
  comp.films = datos.data
  }, function(error){
    console.log(error)
  })
  },
  methods: {
 
    sortLowest() {
      film.title.sort(function(a, b) {
  var nameA = a.name.toUpperCase(); // ignore upper and lowercase
  var nameB = b.name.toUpperCase(); // ignore upper and lowercase
  if (nameA < nameB) {
    return -1;
  }
  if (nameA > nameB) {
    return 1;
  }
 
  // names must be equal
  return 0;
});
 
    }
    }
 
}
 
  </script>
 
<style scoped>
h1, h2 {
  font-weight: normal;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
</style>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder