serverless - In kitsune, how to create a URL format of a details page of an entity without using k-dl?
问题描述
I am trying to create a ecommerce website in kitsune. I do not want to use the _kid value in k-dl. For example, the typical way to do it is -
k-dl="/product/[[product.name.urlencode()]]/[[product.code]]/[[product._kid]]"
If i do not want to use the _kid as its a long GUID. I would like to use code as its unique for every product as the identifier of the specific product.
When i define the k-dl as below it gives me an error that i must use _kid in the URL format:
k-dl="/product/[[product.name.urlencode()]]/[[product.code]]"
解决方案
在 kitsune 中实现对象详细信息页面 URL 的理想方法是具有唯一 id,即_kid以及k-object以获得最佳性能,因为 kitsune 中的对象由_kid唯一标识,它是自动生成的 kitsune id .
但是,是的,有另一种方法可以在没有 kitsune 唯一 ID (_kid) 的情况下实现对象详细信息页面。
如果您想从您的角度维护对象的唯一性,您可以在 kitsune 对象中创建任何唯一字段并如下使用它。因此,如果您使用 k-object,_kid 是必需的,您需要从页面中删除 k-object 属性。
假设product.code是您从K-Admin维护的唯一字段,您可以使用如下的k-dl。
<head k-dl="/product/[[product.name.urlencode()]]/[[product_code_param]]">
这里[[product_code]]是来自 URL 的动态变量,请确保传递正确的产品代码值以生成 URL。
现在你可以通过使用 k-repeat 循环来获得唯一的对象,如下所示
<div k-repeat="[[product in business.products]]">
<div k-show="[[product.code == product_code_param]]"> <!--this will only render if the product code is matching with the url param-->
<p>[[product.name]]</p>
</div>
</div>
推荐阅读
- java - ExecutorService - 并行运行任务并保存结果
- linux - 漏洞利用的 Bash 语法问题
- perl - perl中减法后文件的绝对值
- java - 无法在 cmd 中编译 Helloworld.java
- mysql - 如何从两个数据库表中删除数据
- makefile - Makefile 中的变量替换会产生意想不到的结果
- github - 将 FormSpree 集成到 GitHub Jekyll(返回消息:Form 应该发布)
- python - sqlalchemy concat 在 Oracle DB 上有超过 2 个元素
- google-cloud-platform - 使用不在 IAM 中的用户创建的 Google Cloud 资源
- javascript - 在 html 文件 Flutter 中使用 js 文件