如果您尝试使用以下代码(现已发布在官方网站上),现在会出错。 错误原因是什么?
http://mithril.js.org/mithril.component.html#nesting-components
var App = {
ctrl: function() {
return {data: [1, 2, 3]}
},
view: function(ctrl) {
return m(".app", [
//pressing the button reverses the list
m("button[type=button]", {onclick: function() {ctrl.data.reverse()}}, "My App"),
ctrl.data.map(function(item) {
//the key ensures the components aren't recreated from scratch, if they merely exchanged places
return m.component(MyComponent, {message: "Hello " + item, key: item})
})
])
}
}
var MyComponent = {
controller: function(args) {
return {greeting: args.message}
},
view: function(ctrl) {
return m("h2", ctrl.greeting)
}
}
m.mount(document.body, App)
答案 0 :(得分:0)
controller
应该有ctrl
,而不是var App = {
controller: function() {
return {data: [1, 2, 3]}
},
{{1}}