gpt4 book ai didi

android - Jetpack 组合导航的多个参数

转载 作者:行者123 更新时间:2023-12-03 20:02:18 26 4
gpt4 key购买 nike

如何声明具有多个导航参数的导航路线?我检查了documentation , 和 all of these文章(似乎只是重申了文档所说的内容),而我只能找到带有一个参数的路由示例。
这是我所拥有的:

composable(
route = "createExercise/{exerciseId}",
arguments = listOf(navArgument("exerciseId") { type = NavType.IntType })
) { backStackEntry ->
CreateExerciseScreen(
exerciseId = backStackEntry.arguments!!.getInt("exerciseId"),
)
}
这就是我想要的:
composable(
route = "createExercise/{exerciseId},{workoutId}",
arguments = listOf(
navArgument("exerciseId") { type = NavType.IntType },
navArgument("workoutId") { type = NavType.IntType },
)
) { backStackEntry ->
CreateExerciseScreen(
exerciseId = backStackEntry.arguments!!.getInt("exerciseId"),
workoutId = backStackEntry.arguments!!.getInt("workoutId"),
)
}
我为上面的示例任意选择了逗号分隔的语法来代替我正在寻找的真实语法。
所以,我的问题是: 声明导航路线时,多个参数的正确语法是什么? (那么可选参数呢?)

最佳答案

根据文档:

You can think of it as an implicit deep link that leads to a specific destination.


因此它遵循与任何其他 implicit deep link 相同的约定。和 Web 上 RESTful URL 的约定,通常使用 /分隔不同的参数以形成 URL 的路径 - 这涵盖了所需的参数:
createExercise/{exerciseId}/{workoutId}
根据 optional arguments documentation所需参数的路径可以后跟任意数量的可选参数,形式为一个或多个查询参数:
createExercise/{exerciseId}/{workoutId}?setNumber={setNumber}&repNumber={repNumber}

关于android - Jetpack 组合导航的多个参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65542751/

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