Skip to content

Commit 547f35d

Browse files
panietoarmiljan-aleksic
authored andcommitted
List Rendering section translation (#12)
1 parent e0e90e1 commit 547f35d

File tree

1 file changed

+47
-47
lines changed

1 file changed

+47
-47
lines changed

src/v2/guide/list.md

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
---
2-
title: List Rendering
2+
title: Renderizado de Listas
33
type: guide
44
order: 8
55
---
66

77
## `v-for`
88

9-
We can use the `v-for` directive to render a list of items based on an array. The `v-for` directive requires a special syntax in the form of `item in items`, where `items` is the source data array and `item` is an **alias** for the array element being iterated on:
9+
Podemos usar la directiva `v-for` para renderizar una lista de elementos usando un array. La directiva `v-for` requiere de una sintaxis especial de la forma `item in items`, dónde `items` es el array de datos fuente, e `item` es un **alias** para el elemento del array sobre el cuál se está iterando.
1010

11-
### Basic Usage
11+
### Uso Básico
1212

1313
``` html
1414
<ul id="example-1">
@@ -30,7 +30,7 @@ var example1 = new Vue({
3030
})
3131
```
3232

33-
Result:
33+
Resulta en:
3434

3535
{% raw %}
3636
<ul id="example-1" class="demo">
@@ -56,7 +56,7 @@ var example1 = new Vue({
5656
</script>
5757
{% endraw %}
5858

59-
Inside `v-for` blocks we have full access to parent scope properties. `v-for` also supports an optional second argument for the index of the current item.
59+
Dentro de los bloques `v-for` tenemos acceso completo a las propiedades del ámbito del padre. `v-for` también soporta un segundo argumento opcional para el índice del elemento actual.
6060

6161
``` html
6262
<ul id="example-2">
@@ -79,7 +79,7 @@ var example2 = new Vue({
7979
})
8080
```
8181

82-
Result:
82+
Resulta en:
8383

8484
{% raw%}
8585
<ul id="example-2" class="demo">
@@ -106,15 +106,15 @@ var example2 = new Vue({
106106
</script>
107107
{% endraw %}
108108

109-
You can also use `of` as the delimiter instead of `in`, so that it is closer to JavaScript's syntax for iterators:
109+
También puede usar `of` como el delimitador en vez de `in`, de forma que sea similar al sintaxis de JavaScript para iteradores:
110110

111111
``` html
112112
<div v-for="item of items"></div>
113113
```
114114

115-
### Template v-for
115+
### v-for en template
116116

117-
Similar to template `v-if`, you can also use a `<template>` tag with `v-for` to render a block of multiple elements. For example:
117+
Similar a usar `v-if` en un `<template>`, también se puede usar la directiva `v-for` para renderizar un bloque de múltiples elementos. Por ejemplo:
118118

119119
``` html
120120
<ul>
@@ -125,9 +125,9 @@ Similar to template `v-if`, you can also use a `<template>` tag with `v-for` to
125125
</ul>
126126
```
127127

128-
### Object v-for
128+
### v-for en objetos
129129

130-
You can also use `v-for` to iterate through the properties of an object.
130+
También puede usar `v-for` para iterar sobre las propiedades de un objeto.
131131

132132
``` html
133133
<ul id="repeat-object" class="demo">
@@ -150,7 +150,7 @@ new Vue({
150150
})
151151
```
152152

153-
Result:
153+
Resulta en:
154154

155155
{% raw %}
156156
<ul id="repeat-object" class="demo">
@@ -172,35 +172,35 @@ new Vue({
172172
</script>
173173
{% endraw %}
174174

175-
You can also provide a second argument for the key:
175+
También puede usar un segundo parámetro para la clave:
176176

177177
``` html
178178
<div v-for="(value, key) in object">
179179
{{ key }} : {{ value }}
180180
</div>
181181
```
182182

183-
And another for the index:
183+
Y otro para el índice
184184

185185
``` html
186186
<div v-for="(value, key, index) in object">
187187
{{ index }}. {{ key }} : {{ value }}
188188
</div>
189189
```
190190

191-
<p class="tip">When iterating over an object, the order is based on the key enumeration order of `Object.keys()`, which is **not** guaranteed to be consistent across JavaScript engine implementations.</p>
191+
<p class="tip">Cuando itere sobre un objeto, el orden es basado en el orden de enumeración de claves de `Object.keys()`, el cual **no** tiene garantía de ser consistente a través de implementaciones de JavaScript.</p>
192192

193-
### Range v-for
193+
### v-for de rango
194194

195-
`v-for` can also take an integer. In this case it will repeat the template that many times.
195+
`v-for` puede también tomar un entero. En este caso se repetirá la plantilla ésa cantidad de veces.
196196

197197
``` html
198198
<div>
199199
<span v-for="n in 10">{{ n }}</span>
200200
</div>
201201
```
202202

203-
Result:
203+
Resulta en:
204204

205205
{% raw %}
206206
<div id="range" class="demo">
@@ -211,17 +211,17 @@ new Vue({ el: '#range' })
211211
</script>
212212
{% endraw %}
213213

214-
### Components and v-for
214+
### Componentes y v-for
215215

216-
> This section assumes knowledge of [Components](components.html). Feel free to skip it and come back later.
216+
> Esta sección asume conocimiento en [Componentes](components.html). Siéntase de libre de saltarla y regresar más adelante.
217217
218-
You can directly use `v-for` on a custom component, like any normal element:
218+
Puede usar directamente `v-for` en un componente a medida, como en cualquier elemento normal:
219219

220220
``` html
221221
<my-component v-for="item in items"></my-component>
222222
```
223223

224-
However, this won't automatically pass any data to the component, because components have isolated scopes of their own. In order to pass the iterated data into the component, we should also use props:
224+
Sin embargo, esto no pasa automáticamente datos al componente, ya que los componentes tienen ámbitos aislados propios. Para poder transferir los datos iterados al componente, debemos usar los props:
225225

226226
``` html
227227
<my-component
@@ -231,9 +231,9 @@ However, this won't automatically pass any data to the component, because compon
231231
</my-component>
232232
```
233233

234-
The reason for not automatically injecting `item` into the component is because that makes the component tightly coupled to how `v-for` works. Being explicit about where its data comes from makes the component reusable in other situations.
234+
La razón para no inyectar automáticamente `item` en el componente, es por que haría que el componente sea muy acoplado a cómo funciona `v-for`. Siendo explícito sobre de dónde vienen sus datos hace que el componente sea reusable en otras situaciones.
235235

236-
Here's a complete example of a simple todo list:
236+
Aquí tenemos un ejemplo completo de una lista de tareas:
237237

238238
``` html
239239
<div id="todo-list-example">
@@ -329,29 +329,29 @@ new Vue({
329329
</script>
330330
{% endraw %}
331331

332-
## key
332+
## key (clave)
333333

334-
When Vue.js is updating a list of elements rendered with `v-for`, it by default uses an "in-place patch" strategy. If the order of the data items has changed, instead of moving the DOM elements to match the order of the items, Vue will simply patch each element in-place and make sure it reflects what should be rendered at that particular index. This is similar to the behavior of `track-by="$index"` in Vue 1.x.
334+
Cuando Vue.js está actualizando una lista de elementos renderizados con `v-for`, por defecto usa una estrategia "in-place patch". Si el orden de los elementos de datos cambia, en vez de mover los elementos DOM para ajustar el orden de los elementos, Vue sencillamente arregla cada elemento en su lugar y se asegura que refleje lo que debe ser renderizado en ése índice particular. Ésto es similar al comportamiento de `track-by="$index"` en Vue 1.x.
335335

336-
This default mode is efficient, but only suitable **when your list render output does not rely on child component state or temporary DOM state (e.g. form input values)**.
336+
Este modo por defecto es eficiente, pero sólo recomendable **cuando el renderizado de la lista no dependa del estado de componentes hijos o estado temporal DOM (p.e. valores de campos de formulario)**.
337337

338-
To give Vue a hint so that it can track each node's identity, and thus reuse and reorder existing elements, you need to provide a unique `key` attribute for each item. An ideal value for `key` would be the unique id of each item. This special attribute is a rough equivalent to `track-by` in 1.x, but it works like an attribute, so you need to use `v-bind` to bind it to dynamic values (using shorthand here):
338+
Para darle a Vue una indicación para que pueda rastrear la identidad de cada nodo, y así re-usar y re-ordenar elementos existentes, necesita poveer un atributo único `key` para cada elemento. Un valor ideal para `key` sería el id único de cada elemento. Este atributo especial es un equivalente similar a `track-by` de la versión 1.x, pero funciona como un atributo, de modo que necesita usar `v-bind` para asignar valores dinámicos (usando una versión corta aquí):
339339

340340
``` html
341341
<div v-for="item in items" :key="item.id">
342342
<!-- content -->
343343
</div>
344344
```
345345

346-
It is recommended to provide a `key` with `v-for` whenever possible, unless the iterated DOM content is simple, or you are intentionally relying on the default behavior for performance gains.
346+
Es recomendable usar `key` con `v-for` siempre que sea posible, a menos que el contenido DOM iterado sea sencillo, o intencionalmente dependa del funcionamiento por defecto para aprovechar la eficiencia.
347347

348-
Since it's a generic mechanism for Vue to identify nodes, the `key` also has other uses that are not specifically tied to `v-for`, as we will see later in the guide.
348+
Como es un mecanismo genérico para que Vue identifique nodos, `key` también tiene otros usos que no están específicamente amarrados a `v-for`, como veremos más adelante en la guía.
349349

350-
## Array Change Detection
350+
## Detección de cambio de array
351351

352-
### Mutation Methods
352+
### Métodos de mutación
353353

354-
Vue wraps an observed array's mutation methods so they will also trigger view updates. The wrapped methods are:
354+
Vue envuelve los métodos de mutación de un array observado, de modo que dispare actualizaciones de vista. Los métodos de envoltura son:
355355

356356
- `push()`
357357
- `pop()`
@@ -361,28 +361,28 @@ Vue wraps an observed array's mutation methods so they will also trigger view up
361361
- `sort()`
362362
- `reverse()`
363363

364-
You can open the console and play with the previous examples' `items` array by calling their mutation methods. For example: `example1.items.push({ message: 'Baz' })`.
364+
Puede abrir la consola y jugar con los arrays `items` de los ejemplos anteriores llamando sus métodos de mutación. Por ejemplo: `example1.items.push({ message: 'Baz' })`.
365365

366-
### Replacing an Array
366+
### Reemplazando un Array
367367

368-
Mutation methods, as the name suggests, mutate the original array they are called on. In comparison, there are also non-mutating methods, e.g. `filter()`, `concat()` and `slice()`, which do not mutate the original Array but **always return a new array**. When working with non-mutating methods, you can just replace the old array with the new one:
368+
Los métodos de mutación, como su nombre lo sugiere, mutan el array original del cuál han sido llamados. En comparación, también hay métodos no-mutadores, p.e. `filter()`, `concat()` y `slice()`, los cuales no cambian el array original pero **siempre retornan un nuevo array**. Cuando trabaje con métodos no mutadores, simplemente puede reemplazar el array viejo con el nuevo:
369369

370370
``` js
371371
example1.items = example1.items.filter(function (item) {
372372
return item.message.match(/Foo/)
373373
})
374374
```
375375

376-
You might think this will cause Vue to throw away the existing DOM and re-render the entire list - luckily, that is not the case. Vue implements some smart heuristics to maximize DOM element reuse, so replacing an array with another array containing overlapping objects is a very efficient operation.
376+
Puede estar inclinado a pensar que esto causará que Vue deseche el DOM existente y re-renderice la lista completa - por suerte, ese no es el caso. Vue implementa heurística inteligente para maximizar el re-uso de elementos DOM, de modo que reemplazar un array con otro que contenga algunos elementos en común es una operación muy eficiente.
377377

378-
### Caveats
378+
### Problemas
379379

380-
Due to limitations in JavaScript, Vue **cannot** detect the following changes to an array:
380+
Debido a las limitaciones en JavaScript, Vue **no puede** detectar los siguientes cambios en un array:
381381

382-
1. When you directly set an item with the index, e.g. `vm.items[indexOfItem] = newValue`
383-
2. When you modify the length of the array, e.g. `vm.items.length = newLength`
382+
1. Cuando directamente se cambia un elemento con el índice, p.e. `vm.items[indexOfItem] = newValue`
383+
2. Cuando se modifica el tamaño del array, p.e. `vm.items.length = newLength`
384384

385-
To overcome caveat 1, both of the following will accomplish the same as `vm.items[indexOfItem] = newValue`, but will also trigger state updates in the reactivity system:
385+
Para solventar el problema 1, los siguientes arreglos pueden lograr lo mismo que `vm.items[indexOfItem] = newValue`, pero a su vez activan actualizaciones de estado en el sistema reactivo:
386386

387387
``` js
388388
// Vue.set
@@ -393,17 +393,17 @@ Vue.set(example1.items, indexOfItem, newValue)
393393
example1.items.splice(indexOfItem, 1, newValue)
394394
```
395395

396-
To deal with caveat 2, you can also use `splice`:
396+
Para circunvenir el problema 2, puede usar `splice`:
397397

398398
``` js
399399
example1.items.splice(newLength)
400400
```
401401

402-
## Displaying Filtered/Sorted Results
402+
## Mostrando Resultados Filtrados/Ordenados
403403

404-
Sometimes we want to display a filtered or sorted version of an array without actually mutating or resetting the original data. In this case, you can create a computed property that returns the filtered or sorted array.
404+
A veces queremos mostrar una versión filtrada u ordenada de un array sin mutarlo o cambiando los datos originales. En este caso, podemos crear una propiedad calculada que retorne el array filtrado u ordenado.
405405

406-
For example:
406+
Por ejemplo:
407407

408408
``` html
409409
<li v-for="n in evenNumbers">{{ n }}</li>
@@ -422,7 +422,7 @@ computed: {
422422
}
423423
```
424424

425-
Alternatively, you can also just use a method where computed properties are not feasible (e.g. inside nested `v-for` loops):
425+
Alternativamente, puede sencillamente usar un método si las propiedades calculadas no son la mejor opción (p.e. anidadadas en ciclos `v-for`):
426426

427427
``` html
428428
<li v-for="n in even(numbers)">{{ n }}</li>

0 commit comments

Comments
 (0)