mooml 模板在尝试渲染时返回 null

发布于 2024-10-20 09:30:53 字数 1027 浏览 2 评论 0原文

我正在尝试渲染我即时创建的 mooml 模板,但当我调用 render 时,结果为 null。

这是我的代码:

var myTpl = Mooml.Template('tpl', function() {
  div({class: 'new-container'},
    div({class: 'new-title'},
      div({class: 'new-text'},
        'Put your title here:'
      ),
      div({class: 'new-input'},
        input({type: 'text', name: 'title', class: 'required', title: 'Title'})
      )
    ),
    div({class: 'new-content'},
      form({method: 'post', action: '#'},
        textarea({name: 'content', style: 'width: 100%'})
      )
    )
  );
});

// el is null after executing render
var el = myTpl.render(); 

我查看了 firebug 中的一些变量,发现 myTpl var 不为 null,render 方法也不为 null。我不太了解 mooml 在幕后所做的事情,但我认为我所拥有的应该可以工作,给出以下示例,该示例被发现 这里

var template = new Mooml.Template('mytemplate', function() {
    div('Template on the fly');
});

template.render(); // returns <div>Template on the fly</div>

一如既往,非常感谢任何帮助。

I'm trying to render a mooml template I created on the fly and am getting null when I call render.

Here is my code:

var myTpl = Mooml.Template('tpl', function() {
  div({class: 'new-container'},
    div({class: 'new-title'},
      div({class: 'new-text'},
        'Put your title here:'
      ),
      div({class: 'new-input'},
        input({type: 'text', name: 'title', class: 'required', title: 'Title'})
      )
    ),
    div({class: 'new-content'},
      form({method: 'post', action: '#'},
        textarea({name: 'content', style: 'width: 100%'})
      )
    )
  );
});

// el is null after executing render
var el = myTpl.render(); 

I looked at some of the variables in firebug and the myTpl var isn't null and neither is the render method. I don't know much about what mooml is doing under the hood, but I would think what I have should work given the following example which is found here:

var template = new Mooml.Template('mytemplate', function() {
    div('Template on the fly');
});

template.render(); // returns <div>Template on the fly</div>

As always, any help is much appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧城空念 2024-10-27 09:30:53

嘿,我在看这个时经历了一段可怕的时间,主要是因为你的嵌套标签写得如此混乱,并且寻找不匹配/语法错误,这让我忽略了你未能正确插入类的事实。

var foo = new Mooml.Template('tpl', function() {
    div({"class": 'new-container'},
        div({"class": 'new-title'},
            div({"class": 'new-text'}, 'Put your title here:'),
            div({"class": 'new-input'},
                input({
                      type: 'text',
                      name: 'title',
                      "class": 'required',
                      title: 'Title'
                })
            )
        ),
        div({"class": 'new-content'},
            form({method: 'post', action: '#'},
                textarea({
                    name: 'content',
                    style: 'width: 100%'
                })
            ) // form
        ) // new-content
    ); // end div function
}).render();

foo.inject(document.body);

这有效。 http://jsfiddle.net/YKTyL/2/

注意新的 Mooml.Template 而不是传递对类本身的引用。它就在正确的示例中注视着我们...

另外,我更改了您说 class 的实例:class 之类的东西是 IE 中的保留关键字,需要在“”中引用

heh, i had a horrid time looking at this, mostly because your nested tags are written so messy and looking for a mismatch/syntax error it made me overlook the fact that you fail to insitgate the class properly.

var foo = new Mooml.Template('tpl', function() {
    div({"class": 'new-container'},
        div({"class": 'new-title'},
            div({"class": 'new-text'}, 'Put your title here:'),
            div({"class": 'new-input'},
                input({
                      type: 'text',
                      name: 'title',
                      "class": 'required',
                      title: 'Title'
                })
            )
        ),
        div({"class": 'new-content'},
            form({method: 'post', action: '#'},
                textarea({
                    name: 'content',
                    style: 'width: 100%'
                })
            ) // form
        ) // new-content
    ); // end div function
}).render();

foo.inject(document.body);

this works. http://jsfiddle.net/YKTyL/2/

notice new Mooml.Template as opposed to passing a reference to the class itself. it's staring us right there from the example which is correct...

also, i changed instances where you say class: something as class is a reserved keyword in IE and needs to be quoted in " "

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文