gpt4 book ai didi

node.js - Ember js - 无法使用 urlFor 方法生成带有动态段的 URL

转载 作者:太空宇宙 更新时间:2023-11-03 23:12:06 25 4
gpt4 key购买 nike

当我位于路由 /1/1/orders 中时,我可以使用 urlFor() 生成 URL。但我无法在应用程序路由中生成 URL。

所以这段代码不起作用:

var routeName = "scope.purchase.invoice";
var dynamicSegments = { scopeId: 1, scopeData: 2, invoiceId: 3, pageSize: 20, pageIndex: 1 };
var url = this.router.urlFor(routeName, 1, 2, 3, 10, 1);
console.log("inside generated url", url);

对于这个router.js:

this.route("scope", { path: '/:scopeId/:scopeData' }, function(){
this.route("purchase", function(){
this.route("invoice", { path: '/:invoiceId/:pageIndex/:pageSize' });
})
});

这里是引用ember-twiddle

最佳答案

你的问题是urlFor() takes the models / dynamic segments as individual, ordered params, not a object with keys and values. .

所以这样做:

const url = this.router.urlFor(routeName, dynamicSegments.scopeId, dynamicSegments.scropeData, dynamicSegments.invoiceId, dynamicSegments.pageSize, dynamicSegments.pageIndex);

关于node.js - Ember js - 无法使用 urlFor 方法生成带有动态段的 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59951480/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com