json与页面动态绑定

    function fnBindHtml(html, tempName, data) {
            $(html).find(tempName).each(function () {
                var _this = this;
                var thisNmae = _this.getAttribute('name') ? _this.getAttribute('name'):"err";
                switch (_this.tagName) {
                    case "DIV": { _this.innerHTML = data[thisNmae]; }
                        break;
                    case "P": { _this.innerHTML = data[thisNmae]; }
                        break;
                    case "SPAN": { _this.innerHTML = data[thisNmae]; }
                        break;
                    case "INPUT": { _this.value = data[thisNmae]; }
                        break;
                    default: { _this.innerHTML = data[thisNmae]; };
                        break;
                };
            });
            //return html;
        };

        function fnCreatHtml(rootid, tempName, data) {
            if (data == null || data.length == 0) { return false; }

            for (var i = 0; i < data.length; i++) {
                var rootDivCope = $(rootid).eq(0).clone(true);
                fnBindHtml(rootDivCope, tempName, data[i]);// rootDivCope =                
                $(rootDivCope).show();
                $(rootid).eq(0).after(rootDivCope);
            };
        }

        function fnShowNote(strCode, id) {
            $.ajax({
                url: "/TraceApi/GetOneCameraInfo",
                data: { code: strCode },
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                async: true,//同步异步设置,false同步,true异步
                success: function (res) {
                    if (res.code != "1000") {
                        return;
                    };
                    var modelList = res.data;
                    if (modelList == null || modelList.length == 0) { return; }
                    fnCameraNote(modelList, id);
                }
            });
        };

 

posted @ 2019-05-08 18:15  WangwangJie  阅读(373)  评论(0编辑  收藏  举报