Ember.js 模板未在Ember中绑定模型
我将尝试在ember中绑定模型、控制器和模板 这是我的jsEmber.js 模板未在Ember中绑定模型,ember.js,Ember.js,我将尝试在ember中绑定模型、控制器和模板 这是我的js App = Ember.Application.create({}); App.Person = Ember.Object.extend({ firstName: "r", lastName: "issa" }); App.TestingRoute = Ember.Route.extend({ model: function () { return App.Person.create();
App = Ember.Application.create({});
App.Person = Ember.Object.extend({
firstName: "r",
lastName: "issa"
});
App.TestingRoute = Ember.Route.extend({
model: function () {
return App.Person.create();
},
setupController: function (controller, model) {
controller.set("model", model);
}
});
App.TestingController = Ember.ObjectController.extend({
submitAction: function () {
alert("My model is :" + this.get("model"));
}
});
我的模板是:
<script type="text/x-handlebars" data-template-name="application">
{{render testing}}
</script>
<script type="text/x-handlebars" data-template-name="testing">
{{input valueBinding="model.firstName"}}
{{input valueBinding="model.lastName"}}
<button {{action submitAction target="controller"}} class="btn btn-success btn-lg">Pseudo Submit</button>
<p>{{model.firstName}} - {{model.lastName}}</p>
</script>
{{渲染测试}
{{input valueBinding=“model.firstName”}
{{input valueBinding=“model.lastName”}
伪提交
{{model.firstName}-{{model.lastName}
为什么模板和警报重新运行模型中未绑定的模型为空您的
setupController
和model
方法(来自TestingRoute
的方法)没有被调用。因为控制器是由渲染
视图辅助对象创建的,而不是由转换创建的
例如,使用以下作品:
模板
<script type="text/x-handlebars" data-template-name="testing">
{{input valueBinding="model.firstName"}}
{{input valueBinding="model.lastName"}}
<button {{action submitAction target="controller"}} class="btn btn-success btn-lg">Pseudo Submit</button>
<p>{{model.firstName}} - {{model.lastName}}</p>
</script>
这是小提琴
此外,不推荐在控制器中使用操作,而赞成使用actions:{…}
对象
App = Ember.Application.create({});
App.Router.map(function() {
this.route('testing', { path: '/' })
});
App.Person = Ember.Object.extend({
firstName: "r",
lastName: "issa"
});
App.TestingRoute = Ember.Route.extend({
model: function () {
return App.Person.create();
},
setupController: function (controller, model) {
debugger
controller.set("model", model);
}
});
App.TestingController = Ember.ObjectController.extend({
actions: {
submitAction: function () {
alert("My model is :" + this.get("model"));
}
}
});