Ember CLI - 非常基本的下拉菜单的自定义路由
Ember CLI - Custom routing for very basic dropdown
ember 和 ember cli 的新手,除了 jQuery(不是框架)之外没有任何基于 JS 的框架经验
与 Angular、
中所做的工作相比,我发现自己在一开始就陷入困境
我有一个 REST api `http://localhost:8000/api/groups' 上的组静态列表,那里只有 8 个项目,我需要将它们显示为搜索条件的下拉列表。没什么好看的
我开始创建一个名为 groups
的路线和模型,但应用程序停止工作,我不得不为 group
创建一个与 groups
模型相同的模型,下拉菜单只有 2 个项目
现在我的 ember 应用程序 http://localhost:4200/groups
中有一个 url,我不需要它,我也不希望它存在,
但我忽略了它,不得不创建一个城市下拉列表,api 是
http://localhost:8000/api/cities <-- All cities list, needed for admin
http://localhost:8000/api/cities/active <-- For clients to show active cities so they can add their records
http://localhost:8000/api/cities/filled <-- For users, to show them where clients are available
所以在 ember 中,我为 cities
创建了一个路线和模型,并将相同的模型复制为 city
只是为了在下拉列表中显示城市列表,我需要显示已填充的城市,我创建了 ember g route city/filled
并创建了文件夹,但它的模型也与其他两个模型相同。
Ajax 呼叫没有发送到 city/filled
url,现在我得到了
http://localhost:4200/cities // useless for me
http://localhost:4200/cities/filled //useless for me
在 filled 中,我看到 ajax 调用了两次 http://localhost:8000/api/cities
,加载相同的数据。我尝试在我的应用程序上添加一个下拉菜单并在浏览器中打开 http://localhost:4200/cities/filled
,然后嗖的一声,它向同一个 url 发送 ajax 调用 3 次,一次用于 application.hbs,一次用于cities.hbs 和一个 city/filled。如果在单个请求中已经从相同的 url 中获取相同的数据,为什么还要加载相同的数据 3 次?
在angular我只是调用一个自定义url,我可以得到数据,但是对于ember,这些小东西真的很难掌握,没有帮助大约
active
和 filled
是城市资源的过滤器,它们不是独立的资源,因此您应该尝试将它们用作查询参数。喜欢
http://localhost:8000/api/cities?type=filled
http://localhost:8000/api/cities?type=active
Facebook 将此样式用于查询参数。您还可以使用查询参数来获取资源的分页数据,例如第一页和每页 25 条记录,请求将如下所示:
http://localhost:8000/api/cities?page=1&records=25
ember 和 ember cli 的新手,除了 jQuery(不是框架)之外没有任何基于 JS 的框架经验
与 Angular、
中所做的工作相比,我发现自己在一开始就陷入困境我有一个 REST api `http://localhost:8000/api/groups' 上的组静态列表,那里只有 8 个项目,我需要将它们显示为搜索条件的下拉列表。没什么好看的
我开始创建一个名为 groups
的路线和模型,但应用程序停止工作,我不得不为 group
创建一个与 groups
模型相同的模型,下拉菜单只有 2 个项目
现在我的 ember 应用程序 http://localhost:4200/groups
中有一个 url,我不需要它,我也不希望它存在,
但我忽略了它,不得不创建一个城市下拉列表,api 是
http://localhost:8000/api/cities <-- All cities list, needed for admin
http://localhost:8000/api/cities/active <-- For clients to show active cities so they can add their records
http://localhost:8000/api/cities/filled <-- For users, to show them where clients are available
所以在 ember 中,我为 cities
创建了一个路线和模型,并将相同的模型复制为 city
只是为了在下拉列表中显示城市列表,我需要显示已填充的城市,我创建了 ember g route city/filled
并创建了文件夹,但它的模型也与其他两个模型相同。
Ajax 呼叫没有发送到 city/filled
url,现在我得到了
http://localhost:4200/cities // useless for me
http://localhost:4200/cities/filled //useless for me
在 filled 中,我看到 ajax 调用了两次 http://localhost:8000/api/cities
,加载相同的数据。我尝试在我的应用程序上添加一个下拉菜单并在浏览器中打开 http://localhost:4200/cities/filled
,然后嗖的一声,它向同一个 url 发送 ajax 调用 3 次,一次用于 application.hbs,一次用于cities.hbs 和一个 city/filled。如果在单个请求中已经从相同的 url 中获取相同的数据,为什么还要加载相同的数据 3 次?
在angular我只是调用一个自定义url,我可以得到数据,但是对于ember,这些小东西真的很难掌握,没有帮助大约
active
和 filled
是城市资源的过滤器,它们不是独立的资源,因此您应该尝试将它们用作查询参数。喜欢
http://localhost:8000/api/cities?type=filled
http://localhost:8000/api/cities?type=active
Facebook 将此样式用于查询参数。您还可以使用查询参数来获取资源的分页数据,例如第一页和每页 25 条记录,请求将如下所示:
http://localhost:8000/api/cities?page=1&records=25