我在angular js下构建离子应用程序时遇到问题。 我在互联网上购买了与prestashop在线商店链接的ionic应用程序的源代码,在ionic部分中,我很难在prestashop网站上显示注册国家的列表,图像:error on the returned country list
这是显示器的html文件:
<select name="country" ng-change="changeCountry()" ng-model="userInfo.billing.country">
<option value="">Select a country</option>
<option ng-repeat="country in listCountry" value="{{country.id}}" ng-bind-html="country.name"></option>
</select>
这是控制器:
.controller('CheckoutBillingCtrl', function($scope, $state, $ionicPopup, $rootScope, AppService, UserService, OrderService) {
$scope.userInfo = UserService.getUser();
$scope.listCountry = AppService.getListCountry().then(function(listCountry) {
$scope.listCountry = listCountry;
});
$scope.listState = {};
$scope.changeCountry = function() {
//remove state default
$scope.userInfo.billing.state = '';
};
$scope.checkCountryHasState = function() {
var result = false;
angular.forEach($scope.listCountry, function(country, key) {
if (country.id === $scope.userInfo.billing.country) {
if(country.state && country.state.length !== 0) {
$scope.listState = country.state;
result = true;
}
}
});
return result;
};
$scope.nextStep = function() {
OrderService.updateOrderInfoBilling($scope.userInfo.billing);
if(OrderService.validateOrderInfoBilling()) {
$scope.userInfo.shipping = $scope.userInfo.billing;
UserService.updateUser($scope.userInfo);
$state.go('tab.checkout-note');
}
else {
$ionicPopup.alert({
title: $rootScope.appLanguage.MESSAGE_TEXT,
template: $rootScope.appLanguage.REQUIRED_ERROR_TEXT
});
}
};
})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
这是service.js(从远程站点获取此信息),我想指定在prestashop网站上,我已经安装了一个模块,可以轻松获取站点数据:
angular.module('starter.services', [])
.factory('AppService', function($state, $ionicLoading, $http, $rootScope, $ionicPopup, appConfig, appValue) {
var appSetting = {'thousand_separator': ',', 'decimal_separator': '.', 'number_decimals': 2};
var listCountry = [];
var hasNotification = false;
var disableApp = false;
return {
getDisableApp: function() {
return disableApp;
},
getListCountry: function() {
$ionicLoading.show({
template: '<ion-spinner></ion-spinner>'
});
return $http({
method: 'GET',
url: appConfig.DOMAIN_URL + appValue.API_URL + 'orders?&task=list_countries'
})
.then(function(response) {
$ionicLoading.hide();
// handle success things
if(response.data.status === appValue.API_SUCCESS){
listCountry = response.data.data;
return listCountry;
}
else {
return listCountry;
}
}, function error(response){
$ionicLoading.hide();
$ionicPopup.alert({
title: $rootScope.appLanguage.MESSAGE_TEXT,
template: $rootScope.appLanguage.NETWORK_OFFLINE_TEXT
});
})
;
},
updateAppSetting: function() {
$ionicLoading.show({
template: '<ion-spinner></ion-spinner>'
});
var deviceToken = window.localStorage.getItem("deviceToken");;
return $http({
method: 'GET',
url: appConfig.DOMAIN_URL + appValue.API_URL + 'settings?&token=' + deviceToken
})
.then(function(response) {
$ionicLoading.hide();
// handle success things
if(response.data.status === appValue.API_SUCCESS){
appSetting = response.data.data;
if(appSetting.disable_app && appSetting.disable_app === "1"){
$ionicPopup.alert({
title: $rootScope.appLanguage.MAINTAIN_TEXT,
template: appSetting.disable_app_message
});
disableApp = true;
}
window.localStorage.setItem("appSetting", JSON.stringify(appSetting));
return appSetting;
}
else {
window.localStorage.setItem("appSetting", JSON.stringify(appSetting));
return appSetting;
}
}, function error(response){
$ionicLoading.hide();
$ionicPopup.alert({
title: $rootScope.appLanguage.MESSAGE_TEXT,
template: $rootScope.appLanguage.NETWORK_OFFLINE_TEXT
});
})
;
},
getAppSetting: function() {
if(window.localStorage.getItem("appSetting")){
return JSON.parse(window.localStorage.getItem("appSetting"));
}
else {
return {};
}
}
};
})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
以下是将数据发送到service.js调用的模块代码:
protected function _getResponse()
{
$task = Tools::getValue('task');
// main parameter
$param = Tools::getValue('param');
// other parameter
// get product by type
switch ($task) {
case self::REQUEST_CREATE_CART:
if (!Tools::getValue('line_items') || !Tools::getValue('billing') || !Tools::getValue('shipping')) {
throw new Exception('Invalid parameters');
}
return $this->createCart();
case self::REQUEST_GET_PRICE:
if (!Tools::getValue('line_items') || !Tools::getValue('cart_id')) {
throw new Exception('Invalid parameters');
}
$data = $this->getPrice(Tools::getValue('cart_id'), Tools::getValue('coupon'));
break;
case self::REQUEST_CREATE_ORDER:
if (!Tools::getValue('line_items') || !Tools::getValue('billing') || !Tools::getValue('shipping') || !Tools::getValue('payment_method') || !Tools::getValue('payment_method_title') || !Tools::getValue('shipping_lines')
) {
throw new Exception('Invalid parameters');
}
$data = $this->createOrder();
break;
case self::REQUEST_CHANGE_ORDER_STATUS:
if (!Tools::getValue('id') || !Tools::getValue('status')) {
throw new Exception('Invalid parameters');
}
$data = $this->changeOrderStatus();
break;
case self::REQUEST_LIST_CUSTOMER_ORDER:
$customer_id = intval(Tools::getValue('customer_id'));
if (!$customer_id) {
throw new Exception('Invalid Parameter');
}
$data = $this->getListCustomerOrder($customer_id);
break;
case self::REQUEST_LIST_COUNTRIES:
$data = $this->_getCountryList($param);
break;
default:
$dataObject = new IcymobiData();
Hook::exec(
'actionIcymobi'.$task,
array(
'OrderObject' => $this,
'DataObject' => $dataObject
),
null,
true
);
$data = $dataObject->getData();
break;
}
return $data;
}
public function _getCountryList()
{
if (Configuration::get('PS_RESTRICT_DELIVERED_COUNTRIES')) {
$arrayCountries = Carrier::getDeliveredCountries($this->id_lang_default, true, true);
} else {
$arrayCountries = Country::getCountries($this->id_lang_default, true);
}
foreach ($arrayCountries as &$country) {
$country['id'] = $country['iso_code'];
$country['state'] = array();
if ($country['contains_states'] == 1) {
foreach ($country['states'] as $state) {
$country['state'][$state['iso_code']] = $state['name'];
}
}
unset($country['id_country']);
unset($country['states']);
unset($country['id_lang']);
unset($country['id_zone']);
unset($country['iso_code']);
unset($country['id_currency']);
unset($country['call_prefix']);
unset($country['active']);
unset($country['contains_states']);
unset($country['need_identification_number']);
unset($country['need_zip_code']);
unset($country['zip_code_format']);
unset($country['display_tax_label']);
unset($country['country']);
unset($country['zone']);
}
return ($arrayCountries);
}
问题是在prestashop中注册的国家/地区列表未正确返回,因此什么也不显示。任何帮助都是宝贵的,谢谢!