gpt4 book ai didi

javascript - 点击列表项,页面跳转,但详情页只显示除()外的任何项详细信息

转载 作者:行者123 更新时间:2023-12-02 17:00:28 24 4
gpt4 key购买 nike


目前,主列表 html 有效

 <div class="post row" ng-repeat="(postId, post) in posts">
<a href="{{ post.url }}">{{ post.title }}</a>

但是当我单击该项目(列表中的众多项目之一)并转到另一个页面时,新页面不会详细显示该项目?


当我将下面的行(包括依赖项中的 $stateParams)添加到 Controller js 文件中时,会出现 {{ post.title }} 但数据不会传递。

$scope.post = $scope.posts[$stateParams.id]



更新
这是各州的法规。 (忽略缺少的语法...我正在缩短它)。有人帮助解决了上一个问题,并提供了以下查看部分的代码(最后 2 个状态)。

  .state('tab.view', { 
url: '/posts/:postId',
views: {
'tab-view': {
templateUrl: 'templates/tab-showpost.html',
controller: 'PostViewCtrl'



点击列表项后如何访问详细信息。

app.controller('PostViewCtrl', function ($scope, $stateParams, Post) {
$scope.Post = Post.find($stateParams.postId); //i think this may be broken

最佳答案

您的问题中缺少的一个关键部分是您的 stateProvider 是如何配置的。请确保您的州已正确设置 url,以便通过州参数发送数据。我有a codepen here这显示了一种获得项目列表的方法,其中单击其中一个项目将引导用户查看其详细信息。注意状态是如何设置的...

angular.module('ionicApp', ['ionic'])

.config(function($stateProvider, $urlRouterProvider) {

$stateProvider
.state('tabs', {
url: "/tab",
abstract: true,
templateUrl: "tabs.html"
})
.state('tabs.home', {
url: "/home",
views: {
'home-tab': {
templateUrl: "home.html",
controller: 'HomeTabCtrl'
}
}
})
.state('tabs.detailview', {
url: "/detailview/:index", //NOTE: :index is how you use $stateParams later on.
views: {
'home-tab': {
templateUrl: "detailview.html",
controller: 'DetailviewTabCtrl'
}
}
});


$urlRouterProvider.otherwise("/tab/home");

});

然后,在你的 Controller 中...

.controller('DetailviewTabCtrl', function($scope,$stateParams) {
$scope.id = parseInt($stateParams.index);//NOTE: This is the same 'index'
$scope.previous = parseInt($stateParams.index) - 1;
$scope.next = parseInt($stateParams.index) + 1;
});

关于javascript - 点击列表项,页面跳转,但详情页只显示除()外的任何项详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25770106/

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