本文介绍了试图获取数组内部结构的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java或cfm中寻找一个线性代码,在这里我不需要循环遍历te的结构数组即可使用te structfind从中获取值。

Looking for a one liner code either in java or cfm, where i do not need to loop over te array of structs to use te structfind to get the value from it.

right现在查看它,

right now looking at it,

在这里我可以循环获取

的值,但尝试检查是否可以完成类似的操作

but trying to check if something like this can be done

<cfset myvalue = structfindvaluefromAnything(myarrayofstruct,"infor")>


推荐答案

我喜欢Sev的方法。我会稍作更改

I like Sev's approach. I would change it slightly

<cfscript>
     superheroes=[
           {"name":"Iron Man","member":"Avengers"},
           {"name":"Spider-Man","member":"Avengers"},
           {"name":"Wonder Woman","member":"Justice League"},
           {"name":"Hulk","member":"Avengers"},
           {"name":"Thor","member":"Avengers"},
           {"name":"Aquaman","member":"Justice League"}
     ];

     avengers = superheroes.filter(function(item) {
        return item.member ==  "Avengers";
    });
     writeDump(avengers);
</cfscript>

这篇关于试图获取数组内部结构的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-27 09:25