简体   繁体   English

在Ember数组中,如何通过索引值访问对象? Ember Js

[英]In an Ember Array, how do i access object by index value? Ember Js

For an ember array you can simply do this: 对于ember数组,您可以简单地执行此操作:

array.get('firstObject');

to get the first object in array. 获取数组中的第一个对象。

or this: 或这个:

array.get('lastObject');

to get last object in array. 获取数组中的最后一个对象。

How do I get something by its index? 我如何通过索引得到一些东西? similar to how it works in an ordinary javascript array: 类似于它在普通的javascript数组中的工作方式:

array[index]; 阵列[指数];

Looking at the documentation, you could just do var myObject = array.objectAt(someIndex); 查看文档,你可以做var myObject = array.objectAt(someIndex); , and that will return the object at that specific index. ,这将返回该特定索引处的对象。 You can check the documentation here. 您可以在此处查看文档。

array.get(index)

actually works. 实际上有效。 index can be either an integer or a string. index可以是整数或字符串。


It also works for array-properties, ie. 它也适用于数组属性,即。

this.get('myArray.1')

will return the second element in the myArray property. 将返回myArray属性中的第二个元素。

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

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