【发布时间】:2014-12-11 10:14:15
【问题描述】:
我正在开发 ionic cordova 平台。 在应用程序运行时,我正在读取存储在移动设备上的文件。
在文件读取成功时,我正在存储数据并将其绑定到 $rootScope.Favorites;
但我的收藏地址不具有约束力:
在警报中显示返回的数据。但不更新视图
$cordovaFile.createDir('comMyTaxi', false).then(function(success) {
$cordovaFile.checkFile('comMytaxi/myFavAdd.txt.gz').then(function(
success) {
alert('file found');
$cordovaFile.readAsText('comMytaxi/myFavAdd.txt.gz').then(
function(success) {
// alert(success);
$rootScope.Favorites = [];
var data = JSON.parse(success);
if (data.length > 0) {
for (var v = 0; v < data.length; v++) {
$rootScope.Favorites.push(data[v]);
}
alert($rootScope.Favorites.length);
}
}, function(err) {
//alert('err in reading');
});
}, function(err) {
// alert('no file found');
});
}, function(err) {
// alert('fail file dir');
});
在视图内部我直接绑定 $rootScope.Favorites 变量
<div class="item item-button-right" ng-repeat="Address in Favorites">
<i class="icon ion-ios7-location fontcolorMR FontSize24"></i>
<span class="FontSize14 VerticalAlignTop"> {{Address.Name}} {{Address.Street}} {{ Address.City}} {{ Address.PostCode}}</span>
<button class="button button-clear" ng-click="removeFavorites($index)">
<i class="icon ion-ios7-trash FontColorB" ></i>
</button>
</div>
如何在更改后立即看到?
【问题讨论】:
标签: javascript angularjs cordova