作为学习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>
最终成功了!www.24time.co
可以在www.github.com/stopachka/right-time上找到该代码。
有一种称为会议的模型。
人们通过与Places Autocomplete API进行交互来选择城市。当他们选择时,它将返回latLng职位,这些职位已附加到会议上。一旦模型同时具有城市的两个位置,它就会向/ api / meeting发出ajax请求,并发送位置参数。
API返回所有最佳时间。我敢肯定,我不是用余烬的方式做的,也许可以对模型进行不同的分解,而且时间可以是模型本身。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句