我正在尝试渲染我即时创建的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方法。我不太了解mooml在幕后做了什么,但我会认为我应该使用的是以下示例here:
var template = new Mooml.Template('mytemplate', function() {
div('Template on the fly');
});
template.render(); // returns <div>Template on the fly</div>
与往常一样,非常感谢任何帮助。
答案 0 :(得分:2)
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/
注意new Mooml.Template
而不是传递对类本身的引用。它正是从正确的例子中盯着我们......
另外,我改变了你说类的实例:因为类是IE中的保留关键字,需要引用“”