zoukankan      html  css  js  c++  java
  • jsonp从服务器读取数据并且予以显示

    之前看了许多的关于jsonp的文章,大多是讲的比较的模糊的,下面是我的个人的理解!

    基于这样的一段代码,做下解释: 这是在jsonp中读取数据的时候(取出来当然是json的格式json格式不清楚的,可以访问我的json和jsonp的文章),利用循环进行数据的读取。  先定义变量html,然后循环取出!

    (其实核心就是根据你自己设计的页面结构,比如什么时候用到<div><p><li>等这些,以及之间的关系,然后用循环一次读取存在变量html中)仔细看标签的对应关系

    var html = '';           //定义html变量
    for (var i = 0; i < rows.length; i++) {    //rows[i].length是数组长度
    html += '<div class="item clearfix" onclick="page_company.clickItem(' + rows[i].companyId + ')">' +  //
    '<div class="left"><img src="' + rows[i].picUrl + '"/></div>' 

    + '<div class="right">';
    html += '<div class="title">';
    if(rows[i].companyName)
    html  += rows[i].companyName;
    else
    html  += '暂无';
    html += '</div>';

    html += '<span class="address">';
    if(rows[i].address)
    html += rows[i].address;
    else
    html += '暂无';
    html  += '</span>';

    if(rows[i].distance) {
    html += '<div class="distance">距离:' + rows[i].distance + '</div>';
    }
    html += '<div class="handle">' + 
    '<div class="collection"></div>' +
    '<div class="attention"></div>' +
    '<div style="clear: both;"></div>' +
    '</div>' +
    '</div>' +
    '<div style="clear: both;"></div>' +
    '</div>';
    }

    在循环取出后,用选择器选中页面的要显示的位置(取出的数据和要显示的位置要一致),比如$('#page_company .listview').append(html);注意这里不能用html(html);来显示,如果是用html的话,就只能显示最后一个html,或者是出错!

  • 相关阅读:
    Security and Cryptography in Python
    Security and Cryptography in Python
    Security and Cryptography in Python
    Security and Cryptography in Python
    Security and Cryptography in Python
    Security and Cryptography in Python
    Security and Cryptography in Python
    《EffectiveJava中文第二版》 高清PDF下载
    《MoreEffectiveC++中文版》 pdf 下载
    《啊哈c语言》 高清 PDF 下载
  • 原文地址:https://www.cnblogs.com/ACMxike20111726/p/3253909.html
Copyright © 2011-2022 走看看