简体   繁体   English

如何遍历json列表并嵌入到html中

[英]how to iterate through json list and embed to html

I make an ajax call to retrieve data from a database and the data is returned in the JSON format. 我进行了ajax调用以从数据库检索数据,并且数据以JSON格式返回。 I want to design a "view" to display the data. 我想设计一个“视图”来显示数据。 At best, I just paste the data in the view and the data is displayed. 充其量,我只是将数据粘贴到视图中并显示数据。 Could someone assist me please? 有人可以帮我吗?
Note: the image is for min view the CMS where are suing come with knockOutJS and I am new to this tech 注意:该图像是针对min的,而sockOutJS随附的CMS是我正在使用的新技术

![enter image description here][1] ![在此处输入图片描述] [1]

My source so far: 到目前为止,我的消息来源:

<script type="text/javascript">

    $(function () {

        $("#btnSearch").click(function () {


            $.ajax({
                url: "../ideapark/DesktopModules/ResourcesFilter/AjaxHandler.ashx/",
                dataType: "json",
                type: "POST",
                data: {
                    'action': 'ResponseFilterSearch'
                    , 'Keyword': $('#txtbKeyword value').val()
                    , 'Skill': $("#ddlSkills option:selected").val()
                    ,'Types' : $("#ddlTypes option:selected").val()
                    , 'Topics': $("#ddlTopics option:selected").val()
                    , 'SortBy' : $("#ddlSortBy option:selected").val()
                },
                success: function(data) {
                    for(var i = 0; i < data.length; i++)
                    {
                        //t ajax handler recollection of resources.
                        //U NEED TDESERIALIZE 
                        //var resID = data.response[i].ID;
                        //var summary = data.response[i].Summary;
                        //var pageID = data.response[i].PageID;
                        //var name = data.response[i].Name;
                        //var createdOn = data.response[i].CreatedOn
                        //var Total = data.response[i].Total;



                    }
                },
                error: function(XMLHttpRequest, textStatus, errorThrown)
                {
                    console.log(errorThrown);
                    console.log(XMLHttpRequest);
                    console.log(textStatus);
                    console.log(errorThrown);
                }
            });
        });

    });
</script>

HTML 的HTML

<div class="resourcesResult">
                        <input type="hidden" name="dnn$ctr687$View$rp_resList$ctl00$hf_resID" id="dnn_ctr687_View_rp_resList_hf_resID_0" value="71">
                        <a href="http://ideapark.rtraction.com/WebsofWonder/IWonderWhereTheAnimalsGoInTheFall.aspx">I Wonder Where The Animals Go In The Fall</a>
                        <br>
                        Students begin to understand where the animals in their environment are going in the fall
                        <br>


                                <h6>
                                    <a id="lnkBtnTags_0" href="">observing</a>

                                </h6>

                                <h6>
                                    <a id="lnkBtnTags_1" href="">change</a>

                                </h6>

                                <h6>
                                    <a id="lnkBtnTags_2" href="">animal</a>

                                </h6>

                                <h6>
                                    <a id="lnkBtnTags_3" href="">fall</a>

                                </h6>

                                <h6>
                                    <a id="lnkBtnTags_4" href="">autumn</a>

                                </h6>

                                <h6>
                                    <a id="lnkBtnTags_5" href="">five senses</a>

                                </h6>

                                <h6>
                                    <a id="lnkBtnTags_6" href="">winter</a>

                                </h6>

                                <h6>
                                    <a id="lnkBtnTags_7" href="">hibernation</a>

                                </h6>

                                <h6>
                                    <a id="lnkBtnTags_8" href="">migration</a>

                                </h6>

                                <h6>
                                    <a id="lnkBtnTags_9" href="">adapt</a>

                                </h6>

                                <h6>
                                    <a id="lnkBtnTags_10" href="">seasons</a>

                                </h6>

                        <input type="button" value="Share">

                    </div>


</div

> >

也许您可以使用诸如handbars之类的 javascript templating library

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

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