双向数据绑定的人为示例
var user = {
model: function(name) {
this.name = m.prop(name);
},
controller: function() {
return {user: new user.model("John Doe")};
},
view: function(controller) {
m.render("body", [
m("input", {onchange: m.withAttr("value", controller.user.name), value: controller.user.name()})
]);
}
};
https://lhorie.github.io/mithril/mithril.withAttr.html
我试过上面的代码不起作用。
它是第一个尝试附加以下内容的。
m.mount(document.body, user);
未捕获的 SyntaxError:意外的令牌 n
然后我尝试附加以下内容。
var users = m.prop([]);
var error = m.prop("");
m.request({method: "GET", url: "/users/index.php"})
.then(users, error);
▼/users/index.php
<?php
echo '[{name: "John"}, {name: "Mary"}]';
未捕获的 SyntaxError:意外的令牌 n
如何操作 m.withAttr 教程代码?