Ember CLI-自定义路由,用于非常基本的下拉菜单
ember和ember cli的新手,除了jQuery(不是框架)之外,没有任何基于JS的框架经验
New to ember and ember cli, and not having any JS based framework experience apart from jQuery (which is not a framework)
我发现自己陷入了困境
与Angular中完成的工作相比,我从头开始就有一个静态的组列表,这些列表位于REST api` http:// localhost:8000 / api / groups ,那里只有8个项目,我需要将它们显示为搜索条件的下拉列表。没什么花哨的
I have a static list of groups which are on REST api `http://localhost:8000/api/groups' and it is only 8 items there, I needed to show them as dropdown for a search criteria. Nothing fancy
我从创建名为 groups
的路线和模型开始,但是应用程序停止工作,为 group
创建一个模型,该模型与 groups
模型相同,只有2个下拉项
I started with creating a route and model with the name of groups
but app stopped working and I had to create a model for group
which is identical to groups
model, only having 2 items for dropdown
现在我的余烬应用程序中有一个URL http:// localhost:4200 / groups
我不需要而且我不想要它到那里,
Now i have a url in my ember app http://localhost:4200/groups
which I dont need and i dont want it to be there,
但是我忽略了它,不得不创建一个城市下拉列表,api是
But I ignored it and had to create a dropdown of the cities, api is
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
因此在余烬中,我为城市
创建了一条路线和模型,并将同一模型复制为 city
只是为了显示d中的城市列表ropdown,我需要显示填充的城市,我创建了 ember g route city / filled
并创建了文件夹,但其模型也与其他两个模型相同。
So in ember, I created a route and model for cities
, and same model is copied as city
just to show the list of cities in dropdown, I needed to show cities which are filled, I had created ember g route city/filled
and it created folders, but its model is also same like other two models.
Ajax呼叫未发送到 city / filled
网址,现在我最终拥有
Ajax call is not being sent to city/filled
url and now I ended up having
http://localhost:4200/cities // useless for me
http://localhost:4200/cities/filled //useless for me
填充后,我看到进行了ajax调用,但对 http:// localhost:8000 / api / cities
两次,加载相同的数据。我尝试在我的应用程序上添加一个下拉列表,并在浏览器中打开 http:// localhost:4200 / cities / filled
,然后通过woosh,它将ajax调用发送到相同的URL 3次,一个用于application.hbs,一个用于city.hbs,另一个用于city / filled。如果已经在单个请求中从相同的URL提取了相同的数据,为什么还要加载3次?
and in filled i see that ajax call is made but to the http://localhost:8000/api/cities
two times, loading same data. I tried adding a dropdown on my application and opened http://localhost:4200/cities/filled
in browswer, and woosh, it send ajax call to the same url 3 times, one for application.hbs and one for cities.hbs and one for city/filled. Why load the same data 3 times if it is already fetched from same url within single request?
in angular我只是调用了一个自定义URL,但是我可以获取数据,但是对于余烬来说,很难抓住这些小东西,并且没有任何帮助
in angular I just call a custom url and I can get the data, but for ember its really hard to get grip on these small things and there is no help around
active
和填充
是您的城市资源的过滤器,它们不是独立的资源,因此您应尝试将它们用作查询参数。像
active
and filled
are filters for your cities resource and these are not standalone resources, so you should try to use them as query parameters. like
http://localhost:8000/api/cities?type=filled
http://localhost:8000/api/cities?type=active
Facebook使用此样式来查询参数。您还可以使用查询参数获取资源的分页数据,例如对于第一页和每页25条记录,请求将类似于:
Facebook uses this style for query params. You can also use query params for getting paginated data of a resource, like for 1st page and 25 records per page, the request will look like:
http://localhost:8000/api/cities?page=1&records=25