diff --git a/src/examples/chat/chat.go b/src/examples/chat/chat.go index a2575866..2010b946 100644 --- a/src/examples/chat/chat.go +++ b/src/examples/chat/chat.go @@ -125,6 +125,12 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心", m.Add("append", "name", kit.Chains(value, "conf.name")) m.Add("append", "create_user", kit.Chains(value, "conf.create_user")) m.Add("append", "create_time", kit.Chains(value, "conf.create_time")) + + if list, ok := kit.Chain(value, "text.list").([]interface{}); ok { + m.Add("append", "count", len(list)) + } else { + m.Add("append", "count", 0) + } }) m.Table() return diff --git a/usr/librarys/chat.js b/usr/librarys/chat.js index 488fe8dd..642755cf 100644 --- a/usr/librarys/chat.js +++ b/usr/librarys/chat.js @@ -10,12 +10,17 @@ var page = Page({ page.panes.river = field page.panes.channel = output page.showRiver(page, option) + return {"button": ["添加"], "action": function(value) { + ctx.Run(page, option.dataset, ["river", "create", prompt("name")], function(msg) { + page.showRiver(page, option) + }) + }} }, showRiver: function(page, option) { page.panes.channel.innerHTML = "" page.getRiver(page, option, function(line, index) { page.conf.river = page.conf.river || page.showTarget(page, option, line.key) || line.key - kit.AppendChild(page.panes.channel, [{view: ["item", "div", line.name], click: function(event) { + kit.AppendChild(page.panes.channel, [{view: ["item", "div", line.name+"("+line.count+")"], click: function(event) { if (page.conf.river == line.key) { return } @@ -151,7 +156,15 @@ var page = Page({ var init = page[field.dataset.init] if (typeof init == "function") { var conf = page[field.dataset.init](page, field, option, output) - if (conf) { + if (conf && conf["button"]) { + var buttons = [] + conf.button.forEach(function(value, index) { + buttons.push({"button": [value, function(event) { + typeof conf["action"] == "function" && conf["action"](value, event) + }]}) + }) + kit.InsertChild(field, output, "div", buttons) + } else if (conf) { kit.AppendChild(output, conf) } }