【发布时间】:2014-05-07 02:04:16
【问题描述】:
作为学习 Ember 的一种方式,我正在尝试构建一个简单的应用程序,现在无需借助教程。
应用程序将执行以下操作--
- 用户写自己的城市
- 用户填写他想见的人所在的城市
- 功能将在互惠互利的所有时间吐出。即他们俩都不必太早起床而呆得太晚)
我对如何以 Ember 方式构造数据有点困惑。我该怎么办?
我在想——
会有一个 index.handlebars - 这将为 A 人和 B 的城市提供 2 个输入字段 - 这将得到“会议”模型的支持(属性:cityA,cityB)
当点击提交按钮时,这就是我感到困惑的地方——
我可以想象有一个模型叫做 MeetingTime(有 personA 的时间和 personB 的时间)。
按照 Ember 的最佳实践,我会以什么方式呈现它?什么路由、控制器、模板等?
目前,这就是我所拥有的 ->
RightTime.Router.reopen({
location: 'history'
});
RightTime.Meeting = DS.Model.extend({
myCity: DS.attr('string'),
theirCity: DS.attr('string'),
meetingTimes: function() {
if (myCity && theirCity) {
// get back a collection of meeting times
}
return false;
}.property('myCity','theirCity')
});
RightTime.IndexRoute = Ember.Route.extend({
model: function() {
//return this.store.createRecord('meeting');
//the above return is giving the error 'unedfined is not a function'
}
});
#index.handlebars
<div class="container">
<div class="col-md-6 col-md-offset-3 col-lg-4 col-lg-offset-4">
<header class="animated fadeInDown">
<h1><span class="twenty-four-header">24</span>Time</h1>
<h3>Get Great Meeting Times Instantly</h3>
</header>
<section class="main-options animated fadeInDown">
<div class="form-group">
{{input value=myCity placeholder="What's your city?" class="form-control input-lg"}}
</div>
<div class="form-group">
{{input value=theirCity placeholder="What their city?" class="form-control input-lg"}}
</div>
<div class="form-group">
<button {{action 'getTimes'}} class="btn btn-lg get-times btn-block btn-primary">Get Times!</button>
</div>
</section>
</div>
</div>
【问题讨论】:
标签: javascript ember.js architecture