zoukankan      html  css  js  c++  java
  • 组装数据和页面渲染

    组装数据

    var contacts = new Array();
    $("#contact").find('div').each(function() {
    if ($(this).hasClass('contList')) {
    if ($(this).find('div').find('input[name="linkman"]').val() || $(this).find('div').find('input[name="phone"]').val() || $(this).find('div').find('input[name="email"]').val()) {
    var contactsJsonStr = dataHelper.setJson(null, "linkman", $(this).find('div').find('input[name="linkman"]').val());
    contactsJsonStr = dataHelper.setJson(contactsJsonStr, 'phone', $(this).find('div').find('input[name="phone"]').val());
    contactsJsonStr = dataHelper.setJson(contactsJsonStr, 'email', $(this).find('div').find('input[name="email"]').val());
    contacts.push(jQuery.parseJSON(contactsJsonStr));
    }
    }
    });
    jsonstr = dataHelper.setJson(jsonstr, "contacts", contacts); //联系方式集合

    页面渲染数据

    $.each(data.payload.contacts, function(index, entry) {
    $("#contact").find('div').each(function() {
    if ($(this).hasClass('contList')) {
    if ($(this).index() == index) {
    $(this).find('div').find('input[name="linkman"]').val(entry.linkman);
    $(this).find('div').find('input[name="phone"]').val(entry.phone);
    $(this).find('div').find('input[name="email"]').val(entry.email);
    }
    }
    })
    });

    知识点:

    function (index, value)index前元素位置value值

     // each处理维数组   var arr1 = [ "aaa", "bbb", "ccc" ];         

    $.each(arr1, function(i,val){             alert(i);          alert(val);   });  

     // 处理json数据例ajax返值        var obj = { one:1, two:2, three:3};        

    $.each(obj, function(key, val) {             alert(key);        alert(val);    });

    不忘初心,方得始终,初心易得,始终难守。
  • 相关阅读:
    如何将 asp.net core 应用进行 docker 容器部署
    三步搞定Centos 7 上特定版本的 docker 安装
    docker常用命令整理-在容器中使用service命令
    超简单,Centos7 安装 rabbitMQ
    C# 异步编程4 async与await 异步程序开发
    了解php的session_start的工作原理
    使用php-emoji类让网页显示emoji表情
    php拓展ssh功能
    HTML5的Server-Sent Events功能的使用
    apache的日志查看与开启
  • 原文地址:https://www.cnblogs.com/chuxinsyn/p/7999957.html
Copyright © 2011-2022 走看看