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

    不忘初心,方得始终,初心易得,始终难守。
  • 相关阅读:
    todo-list
    codeforces 794 (#414 DIV1+DIV2)
    2018bnu校赛总结
    codeforces 743D
    HDU-2196 Computer (树形DP)
    HDU- 1005 Number Sequence(矩阵快速幂)
    HDU- 4000 Fruit Ninja(树状数组)
    codeforces 505C
    codeforces 286B
    codeforces 3D
  • 原文地址:https://www.cnblogs.com/chuxinsyn/p/7999957.html
Copyright © 2011-2022 走看看