对于单选题,有没有替代“.each”方法的方法


Is there an alternative to the `.each` method for single selection?

我从数据库中提取了以下信息。

function start(){
  $.get("map_process.php", function (data){
    $(data).find("marker").each(function (){
     var name = $(this).attr('name');
     var verified = $(this).attr('verification');
     + others...
)};
)};
}

最终,这些被用来为谷歌地图创建标记。这可以很好地工作,并为数据库中的每个条目创建标记,但当执行其他函数时,我需要能够仅"更新"一列的值。我很确定这个过程是正确的,但我只是不知道我能做些什么来只获取一个条目的值,而不是每个的值。有我能做的吗?-比如用与一个条目相关的其他内容替换.each

也许您想使用jquery index()来选择特定的元素,如下所示:

$(data).find("marker").index(0)

一个好的解决方案是找到具有指定属性的标记:

$(data).find("marker[name='your name']")

这将选择一个具有指定名称的标记。

来源:

http://api.jquery.com/attribute-equals-selector/