简体   繁体   中英

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. 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

![enter image description here][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

<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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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