gf icon indicating copy to clipboard operation
gf copied to clipboard

gf 模板渲染语法在js中使用 如 {{if .Context.User}} 会导致js 语法错误提示。请问有什么方法可以解决吗?使用的是goland

Open b1lz9 opened this issue 3 years ago • 1 comments

如下面这段是官方focus-single demo 中的一小段js 代码。使用了goland 打开会报很多语法错误。

一直不敢在js中时使用模板语法,请问可以怎么避免一下吗?

                success: function (r) {
                    $('.reply-list').remove();
                    const replyList = $(r.data.content);
                    for (let i = 0; i< replyList.length; i ++) {
                        if (replyList[i].nodeName === "LI") {
                            $('.comment-num')[0].append($(r.data.content)[i]);
                        }
                    }

                    // 采纳展示,如有有已经被采纳,那么其他全部隐藏
                    $("[id^='adopted_btn_']").hide();
                    if("{{.Data.Content.AdoptedReplyId}}"=="0"){
                        // 只有作者可以采纳
                        {{if .Context.User}}
                        {{if eq .Context.User.Id .Data.Content.UserId }}
                        $("[id^='adopted_btn_']").show();
                        {{ end }}
                        {{end}}
                    }else{
                        $("#adopted_it_{{.Data.Content.AdoptedReplyId}}").show();
                    }
                    
                },

b1lz9 avatar Jul 30 '22 04:07 b1lz9

装个smarty插件,用它来打开。我用vscode是这样处理的

sanrentai avatar Aug 12 '22 02:08 sanrentai