【问题标题】:How do I structure a Timezone Checking App in Ember如何在 Ember 中构建时区检查应用程序
【发布时间】: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


    【解决方案1】:

    终于成功了! www.24time.co

    代码可以在 www.github.com/stopachka/right-time 找到

    有一种模型叫做会议。

    人们通过与 Places Autocomplete API 交互来选择城市。当他们选择时,它会返回附加到会议的 latLng 位置。一旦模型拥有两个城市的位置,它就会向 /api/meeting 发出 ajax 请求,发送位置参数。

    API 返回所有最佳时间。不过我很确定我不是用 ember 的方式做的,也许模型可以以不同的方式分解,而时代本身也可以是模型。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-22
      • 1970-01-01
      • 2014-10-01
      • 2018-06-23
      • 1970-01-01
      • 2015-02-25
      相关资源
      最近更新 更多