English 中文(简体)
请求 选择Array
原标题:JQUERY Looping an Array
  • 时间:2012-04-18 05:53:40
  •  标签:
  • jquery

我有一个AJAX阵阵阵列,返回联合请求:

“entergraph

如果我这样做的话,我可以看到阵列:

 alert(data);

我然后通过JSON密码操作如下阵列:

 var obj = JSON.parse(data);

现在,我需要能够从阵列和接触这些要素。 我尝试了几种方法,但我看不去看一下这些要素——例如:如页数所示的分类错误。

这是我尝试的方法之一:

obj.each(function(key, value) {
    alert(key + ": " + value);
}

缺少一些东西——任何帮助都会得到真正的赞赏。

th

问题回答
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="Scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            var data =  [{ "metatype": "descriptions", "pagename": "index", "metacontent": "testing1" }, { "metatype": "keywords", "pagename": "index", "metacontent": "testing2" }, { "metatype": "title", "pagename": "index", "metacontent": "testing3"}] ;
            var obj = JSON.parse(data);

            $.each(obj, function (i, entity) {
                $( #result ).append( <div>  + i + ": " + entity.metatype +     + entity.pagename +     + entity.metacontent +  </div> );
            });
        }); 
    </script>
</head>
<body>
    <div id="result">
    </div>
</body>
</html>

    enter code here




相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签