underscore.js의 사용

3302 단어
html 요소underscore 삽입 템플릿
 

획득 시간
        var QueryForm = {
            el: $("#query-form"),
            init: function () {
                this.el.on('click', '.btn-filter', function () {
                    Chart.get();
                    BizDetail.init()
                });
                this.el.find('.time-start').datetimepicker({
                    format: 'YYYY-MM-DD',
                    locale: 'zh-cn',

                }).on('dp.change', function (e) {
                    var date = e.date.format('YYYY-MM-DD');
                }).on('hide', function (e) {
                });
                this.el.find('.time-end').datetimepicker({
                    locale: 'zh-cn',
                    format: 'YYYY-MM-DD',
                }).on('changeDate', function (e) {
                }).on('changeYear', function (e) {
                });
                return this;
            },

            getData: function () {
                return this.el.serializeArray();
            }
        };
 
        <tr>
            <th><%=date%></th>
            <th><%=register_num%></th>
            <th><%=income%></th>
            <th><%=visit_num%></th>
            <th><%=join_num%></th>
        </tr>
    
var BizDetail = {
            api: '{% url 'each_biz_api'%}' + '?id=' + biz_id,
            tmpl_detail: _.template($('#each_detail').html()),
            onData: function (json) {
                if (json.status === 200) {
                    var chain = _.sortBy(json.data,'date');
                    var html_detail = _.map(chain, function (item, idx) {
                        return this.tmpl_detail(item);
                    }.bind(this)).join('');
                    $('#biz_detail').html(html_detail);
                }
            },

            init: function () {
                var data = QueryForm.getData();
                console.log(data)
                $.get(this.api, data, this.onData.bind(this), 'json');

            }
        };

좋은 웹페이지 즐겨찾기