Closed PalaChen closed 2 years ago
golang
utton := []Button{ {Name: "admin", Link: "/system/"}, {Name: "index", Link: "/"}, } links := "" var btns []string for i, btn := range button { links += fmt.Sprintf("btn.find('.layui-layer-btn%v').attr({href: '%v',target: '_blank'});", i, btn.Link) btns = append(btns, btn.Name) }
template
<script> {% if btns|length==0 %} layer.msg({{ message }}) {% else %} layer.open({ type: 1 ,title: false ,closeBtn: false ,area: '300px;' ,shade: 0.8 ,id: 'LAY_layuipro' ,btn:{{ btns}} ,btnAlign: 'c' ,moveType: 1 ,content: '<div style="padding: 50px; line-height: 22px;font-weight: 300;">{{message}}</div>' ,success: function(layero) { var btn = layero.find('.layui-layer-btn'); {{links | safe}} } }) {% endif %} </script>
html
layer.open({ type: 1 ,title: false ,closeBtn: false ,area: '300px;' ,shade: 0.8 ,id: 'LAY_layuipro' // ,btn:["admin","index"] this i want to ,btn:<[]string Value> ,btnAlign: 'c' ,moveType: 1 ,content: '<div style="padding: 50px; line-height: 22px;font-weight: 300;">success</div>' ,success: function(layero) { var btn = layero.find('.layui-layer-btn'); btn.find('.layui-layer-btn0').attr({href: '/system/',target: '_blank'});btn.find('.layui-layer-btn1').attr({href: '/',target: '_blank'}); } })
Solve using string concatenation
golang
template
html