簡體   English   中英

僅具有屬性值的AS3對象列表搜索

[英]AS3 Object List Search with Attribute Value Only

假設我有一個自定義類型的對象列表,並且我需要找到一個僅給出其屬性之一的值的對象,我該怎么做?

例如。

  // Where user1 ... usern are objects of some class User
  users = [ user1, user2, user3 ... usern ] 

  // How do I find out the objects that have the "foo" attribute set to "bar"

您可以使用數組的filter()方法

var fooBarUsers:* = users.filter(function (user:User) {
    return user.foo == "bar";
});

要基於屬性排序,請使用sortOn方法

fooBarUsers.sortOn("foo");          // Sorts in-place by default

sortOn()方法有很多選項。 請務必閱讀文檔。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM