用Ember.js lug lug。 [英] Slug urls with Ember.js

查看:135
本文介绍了用Ember.js lug lug。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你如何获得 post / my-title (使用自定义段)而不是 posts / 2 (与id)在Ember.js?

How would you get post/my-title (with a custom slug) instead of posts/2 (with id) in Ember.js?

我的方法是在我的模型中添加和使用一个小插件,但它不能直接访问。使用 {{link-to}} 帮助器,它也是lug。。我假设错误在于 PageRoute 的模型。尝试返回this.store.find('page',{'slug':params.page_slug})没有任何运气。

My approach was to add and use a slug in my model but it doesn't work on direct access. Using a {{link-to}} helper it works, also the slug. I assume the error lies in the PageRoute's model. Tried return this.store.find('page', {'slug': params.page_slug}) without any luck.

示例代码: http://emberjs.jsbin.com/AVAgUZAb/5/edit

推荐答案

您是Ember Data不兼容的版本。在 PageRoute 中,您正在使用模型定义来尝试查找不再正确的记录。请参阅 https://github.com/emberjs/data/blob/master/TRANSITION。 md

You're mismatching versions of Ember Data. In the PageRoute you are using the model definition to try and find the record which is no longer correct. See https://github.com/emberjs/data/blob/master/TRANSITION.md

此外,您实际上应该只是使用slug替换 id ,因为您已基本呈现独一无二的项目的想法(aka slug 不一定是唯一的,但是 id 你有多个项目具有相同的s lug?)如果你的s子永远是唯一的,你也可以使用它们作为 id 没有约束,id必须是数字。

Additionally you really should just replace id with the slug since you've essentially rendered the idea of unique items worthless (aka slug doesn't have to be unique, but id does, so what happens when you have multiple items with the same slug?) If your slugs will always be unique, you might as well use them as the id there is no constraint that id must be numeric.

http://emberjs.jsbin。 com / AVAgUZAb / 9 / edit

这篇关于用Ember.js lug lug。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆