gpt4 book ai didi

javascript - 根据 Angular JS 中的 ID 将一页数据发送到另一个寻呼机

转载 作者:行者123 更新时间:2023-11-29 21:34:29 25 4
gpt4 key购买 nike

我正在使用移动 Angular js UI 框架工作。我是 angular js 的新手,想将数据一页发送到具有城市 ID 的另一页。如果用户点击城市,则根据城市显示数据。

首页:
enter image description here

HTML 页面:

  <div class="jumbtron scrollable-content text-center bg-color">
<div class="row">
<div class="bgImage">
<div class="bannerCntnt">
<div class="hp-text-bnnr" style="color:white"> WHERE DO YOU WANT DELIVERY? <br>CHOOSE CITY </div> <br>
<div class="btn-group" ng-controller="MyController">
<button ui-turn-on='myDropdown' class='btn' ng-click="getDataFromServer()"
style="width:160px;background-color:white; color:#c62222">
<span class="fa fa-location-arrow"></span>
<strong>
Select City
</strong>
</button>
<ul class="dropdown-menu scrollableMenu" role="menu" ui-outer-click="Ui.turnOff('myDropdown')" ui-outer-click-if="Ui.active('myDropdown')" role="menu"
ui-show="myDropdown" ui-state="myDropdown" ui-turn-off="myDropdown" style="margin-top:0 px;margin-top:-1px; text-align:center;height:300px; overflow: scroll;">
<li ng-repeat="city in cities">
<a ng-href="#/cityPage" style="color:#763428; font-weight:bold;">{{ city.cityName }}</a>
</li>

</ul>
</div>
</div>
</div>
</div>
</div>

主页 Controller :

.controller('MyController' ,function ($scope, $http) {
$scope.getDataFromServer = function() {
$http({
method : 'GET',
url : 'http://192.168.0.3/sf/app/cityName',
headers: {'Content-Type': 'application/json'},

}).success(function(data, status, headers, config) {
$scope.cities = data;
$scope.cities.forEach(function(product) { Console.log(product.cityId);

});

}).error(function(data, status, headers, config) {
})

}
})

当用户从下拉列表中单击任何选择的城市时,所有城市 ID 都会出现在控制台中。单击下拉城市后,将出现下一页。

屏幕截图:
enter image description here

HTML 代码:

<div class="jumbtron scrollable-content text-center bg-color">
<div class="row">
<div class="bgImage">
</div>
<div class="btn-group img-responsive" ng-controller="MyControllerCity">
<div ng-repeat="prdct in cityProduct">
<a href="#/category-prduct" style="color:#763428; font-weight:bold;">
<img src="{{prdct.categoryImage}}">
</a>
</div>
</div>

</div>
</div>

Controller :

.controller('MyControllerCity',function($scope, $http){ 
$http({
method:'get',
url:'http://192.168.0.3/sf/app/city-home/1',
headers: {'Content-Type': 'application/json'},
}).success(function(data, status,headers, config) {
$scope.cityProduct = data;
$scope.cityProduct.forEach(function(product) {
console.log(product.categoryId);
console.log("--------------------------");

});
console.log("All ID"+$scope.cityProduct[0].categoryId);
}).error(function(data, status, headers ,config) {
})
})

您可以通过这个网址查看哪个城市有多少产品:

> https://www.winni.in/app/city-home/12
> https://www.winni.in/app/city-home/1
> https://www.winni.in/app/city-home/2

enter image description here

APP.JS

angular.module('Y', [
'ngRoute',
'mobile-angular-ui',
'Y.controllers.Main'
])

.config(function($routeProvider) {
$routeProvider.when('/', {templateUrl:'home.html', reloadOnSearch: false})
.when('/cityPage', {templateUrl:'cityPage.html', reloadOnSearch: false})
.when('/category-prduct', {templateUrl:'category-prduct.html', reloadOnSearch: false})
.when('/product-description', {templateUrl:'product-description.html', reloadOnSearch: false})
.when('/my-winni', {templateUrl:'my-winni.html', reloadOnSearch: false})
.when('/gift-box', {templateUrl:'gift-box.html', reloadOnSearch: false});
});

我想根据城市ID在下一页显示数据。

We can find the city ID from this url http://www.winnni.in/app/cityName And append on this url: https://www.winni.in/app/city-home/12

最佳答案

你已经在路由文件中使用了 routeParam,就像我在下面的代码中所做的那样,并且必须通过 $routeParam 在其他 Controller 中获取传递的参数。这是一个例子:

index.html

<!DOCTYPE html>
<html ng-app="myApp">
<head>
<title></title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.5/angular-route.min.js"></script>
</head>
<body>

<div ng-view></div>

<script>
var app = angular.module('myApp', []);
app.config(['$routeProvider',
function($routeProvider)
{
$routeProvider.
when('/city',
{
templateUrl: 'city.html',
controller: 'cityController'
}).
when('/city/:city_id',
{
templateUrl: 'city_id.html',
controller: 'CityIdController'
}).
otherwise({
redirectTo: '/'
});
}]);


app.controller('cityController', function($scope)
{
$scope.city_data = [
{id:1,
name:'Rajkot'},
{id:2,
name:'Morbi'}
];
});

app.controller('CityIdController', function($scope,$routeParams)
{
console.log($routeParams.city_id);
$scope.city_id = $routeParams.city_id;
});
</script>
</body>
</html>

城市.html

<div ng-repeat="x in city_data">
<a href="#/city/{{x.id}}">{{x.name}}</a>
</div>

city_id.html

Clicked City Id is : {{city_id}}

关于javascript - 根据 Angular JS 中的 ID 将一页数据发送到另一个寻呼机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35225465/

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