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);    });

    不忘初心,方得始终,初心易得,始终难守。
  • 相关阅读:
    深度学习中的基本概念——梯度相关
    模型训练中涉及到的技巧
    ubuntu swapfile
    ubuntu install opencv
    Jetson TX1 安装ROS操作系统
    Redis介绍以及安装(Linux)
    C# url信息获取
    贝茨视觉训练法
    PHP设计模式浅析
    MySQL相关知识
  • 原文地址:https://www.cnblogs.com/chuxinsyn/p/7999957.html
Copyright © 2011-2022 走看看