【发布时间】:2015-01-12 18:55:52
【问题描述】:
我在更新我的 ionic 框架幻灯片时遇到了问题。我整理了一个jsfiddle,它是目前的形式,没有功能,但是,你可以在那里看到代码。
我的问题是,如果仅出于测试目的,我在加载页面时使用 ajax,它工作得很好。如果我使用超时来模拟异步,它也可以工作。
如果我在 ngSubmit 上设置了一个函数,则幻灯片不会更新,但是,ajax 的成功部分会检索数据。我也可以在html端打印,但是幻灯片没有更新。
谁能告诉我为什么?
HTML:
<ion-view view-title="Search" ng-controller="UserSearchCtrl" class="title-left">
<ion-content scroll="false">
<div class="list">
<form ng-submit="retrieveResults()" ng-controller="UserSearchCtrl">
<input type="text" placeholder="Search" ng-model="criteria">
</form>
</div>
<div class="search-results">
<ion-slide-box show-pager="false">
<ion-slide ng-repeat="user in result.users" class="img-box-6">
{{user}}
</ion-slide>
</ion-slide-box>
</div>
</ion-content>
</ion-view>
JavaScript,不工作:
engine.module.controller('UserSearchCtrl', function($scope, $rootScope, $http, $ionicSlideBoxDelegate, $timeout, $state, $stateParams, $db, $user) {
$ionicSlideBoxDelegate.enableSlide(false);
$scope.width = window.outerWidth;
// if I wrap the below ajax fn in a function, called on submit, it stops working
$scope.retrieveResults = function() {
var token = $rootScope.user.token;
if ($scope.criteria !== '') {
$http.get(engine.config.REMOTE_URL + '/search?' + 'token=' + token)
.success(function(response) {
$scope.result = response.data;
// debug - they both alert the same thing
//alert(response.data.search_type);
//alert($scope.result.search_type);
$ionicSlideBoxDelegate.enableSlide(true);
$ionicSlideBoxDelegate.update();
})
} else {
// ALERT: criteria is not set
}
};
});
JavaScript,无需 ngSubmit 即可工作:
engine.module.controller('UserSearchCtrl', function($scope, $rootScope, $http, $ionicSlideBoxDelegate, $timeout, $state, $stateParams, $db, $user) {
$ionicSlideBoxDelegate.enableSlide(false);
$scope.width = window.outerWidth;
//$scope.retrieveResults = function() {
var token = $rootScope.user.token;
if ($scope.criteria !== '') {
$http.get(engine.config.REMOTE_URL + '/search?' + 'token=' + token)
.success(function(response) {
$scope.result = response.data;
$ionicSlideBoxDelegate.enableSlide(true);
$ionicSlideBoxDelegate.update();
})
} else {
// ALERT: criteria is not set
}
//};
});
更新 如果我在点击时调用该函数,它也可以工作。似乎只有在提交调用更新它的函数时幻灯片才起作用..
【问题讨论】:
-
解决了吗,或者你需要什么东西吗?
标签: ajax angularjs angularjs-ng-repeat ionic-framework