在kancloud.js里

    initHighlighting();
    window.jsTree = $("#sidebar").jstree({
        'plugins': ["wholerow", "types"],
        "types": {
            "default": {
                "icon": false  // 删除默认图标
            }
        },
        'core': {
            'check_callback': true,
            "multiple": false,
            'animation': 0
        }
    }).on('select_node.jstree', function (node, selected) {
        //如果是空目录则直接触发展开下一级功能
        if (selected.node.a_attr && selected.node.a_attr.disabled) {
            selected.instance.toggle_node(selected.node);
            return false
        }
        $(".m-manual").removeClass('manual-mobile-show-left');
        loadDocument(selected.node.a_attr.href, selected.node.id, selected.node.a_attr['data-version']);
    });

如上代码所示,.on('select_node.jstree', function (node, selected)是点击目录触发的事件,然后调用loadDocument,里面采用ajax请求:

function loadDocument($url, $id, $callback) {
    $.ajax({
        url: $url,
        type: "GET",

请求到documentcontroller.go里的判断:

// 阅读文档
func (c *DocumentController) Read() {
    if c.IsAjax() {
        var data struct {
            DocId         int    `json:"doc_id"`
            DocIdentify   string `json:"doc_identify"`
            DocTitle      string `json:"doc_title"`
            Body          string `json:"body"`
            Title         string `json:"title"`
            Version       int64  `json:"version"`
            ViewCount     int    `json:"view_count"`
            MarkdownTheme string `json:"markdown_theme"`
            IsMarkdown    bool   `json:"is_markdown"`
上一篇:
下一篇: