Bootstrap + Mithril HTML表格渲染

时间:2015-11-27 15:39:09

标签: twitter-bootstrap mithril.js

我无法让Mithril渲染任何Bootstrap表。我有使用以下(基本)代码渲染的Bootstrap按钮元素:

 var TableModule = {
      view: function(){
          return [
             m("button.btn btn-lg btn-primary", { onclick: function () { alert("derr"); } }, "Teh Button"),
             m("table.table table-striped",
                  m("tr", [m("td", "herp"), m("td", "derp")]))
          ]
      }
  } 
  m.module(document.getElementById("test4"), TableModule);

如果我使用以下方法对表进行硬编码:

<table class="table table-striped"><tr><td>herp</td><td>derp</td></tr></table>

(这与上面的Mithril代码完全相同的html)我得到以下内容: enter image description here

想法,想法,建议?欢迎任何欢迎。

3 个答案:

答案 0 :(得分:3)

在Mithril中添加静态CSS类时,建议您使用. CSS选择器语法,请参阅此section

所以你的代码应该是:

var TableModule = {
          view: function(){
              return [
                 m("button.btn.btn-lg.btn-primary", { onclick: function () { alert("derr"); } }, "Teh Button"),
                 m("table.table.table-striped",
                      m("tr", [m("td", "herp"), m("td", "derp")]))
              ]
          }
      }

m.mount(document.getElementById("test4"), TableModule);

@ciscoheat的其他评论也有效。您应该在较新版本的Mithril中使用m.mountm.route

答案 1 :(得分:2)

可能很简单,您需要拨打m.mount而不是m.module。模块也是0.2之前的概念,组件正在被使用。 (没有那么大的区别,但值得一读:http://mithril.js.org/mithril.component.html

修改:尝试在m调用中的类之间添加点。例如button.btn.btn-lg.btn-primary

答案 2 :(得分:0)

你需要将TB包裹在TBODY中。这似乎是由Bootstrap自动完成的,但在使用v-nodes和m-helper时却没有。