htmlBuilder.js 1.6 KB
var __html_builder = {

    builderListPageBtns : function(btns){
        var text = "";              
        var _btn_datas = []; 
        if(btns){
            _btn_datas = btns;
        } else{//default 
            _btn_datas = [
                {role : "edit", text : "编辑"},
                {role : "delete", text : "删除"}
            ]; 
        }              
        _btn_datas.forEach(function(obj,index){
            var _edit = $("<a style='margin-left:10px'></a>");
            _edit.attr("role", obj.role);
            if(obj.data){
                _edit.attr("data", obj.data);
            }            
            _edit.text(obj.text);
            text += _edit.get(0).outerHTML;
        });
        
        return text;
    },

    buildSelect : function(param){
        var _select = $("<select></select>");

        _select.attr(param.attr);
        _select.css(param.css);
        var _option_datas = param.option_datas || [] ;
        var _options_html = "<option value=\"\">请选择</option>";
        _option_datas.forEach(function(_optioin_val,_index){
            _options_html += "<option value=\""+ _optioin_val.en_name +"\">"+ _optioin_val.cn_name +"</option>";
        });
        _select.append(_options_html);
        return _select;
    },
    buildInput : function(_props){
        var text = "";
        var default_props = { type : "text"};
        if(_props){
            $.extend(default_props, _props);
        }
        var _input = $("<input />");
        $.each(default_props,function(key,val){
            _input.attr(key,val);
        })
        return _input.get(0).outerHTML;
    }

}