4

我正在使用 Appgyver Steroids 和 AngularJs 开发一个 HTML5 移动应用程序。该应用程序使用全局 javascript 对象来填充步骤中的信息,并由整个应用程序使用。在我需要创建一个 gallery.html 并将其作为 Web 层从我的主控制器推送之前,一切都运行良好。main.html 和gallery.html 有自己的控制器。Gallery.html 按预期从 javascript 对象显示所有图片,当我删除它们时,它们也按预期从 javascript 对象中删除。但是,当我返回 main.html 并单击“图库”时,它们又都出现在了 gallery.html 中。

我认为一定存在范围问题或多个实例的问题?如何让gallery.html 读取实际对象(完全删除后没有图片的对象)?为什么gallery.html 不更新其值?我一直在运行代码,它没有任何问题,但是当我在 web 层中使用它时,就会发生这种情况。

在主控制器中:

$scope.gallery = function(roomId, detailId) {
    pictures = inspectionService.getPictures(roomId, detailId);

    if (pictures.length > 0) {
        webView = new steroids.views.WebView("/views/inspection/gallery.html?roomId=" + roomId + '&detailId=' + detailId);
        steroids.layers.push(webView);
    } else {
        this.camera();
    }
};

在画廊控制器中:

function init(){
    roomId = steroids.view.params.roomId;
    detailId = steroids.view.params.detailId;
    updateGallery();
}

//UPDATING GALLERY
function updateGallery() {
    $scope.pictures = inspectionService.getPictures(roomId, detailId);
    $scope.info = inspectionService.getRoom(roomId).name + ": " + inspectionService.getDetail(roomId, detailId).name;
};

//REMOVE PICTURE
$scope.removePicture = function(pictureUri) {
    inspectionService.removePicture(roomId, detailId, pictureUri);
    updateGallery();

    if (pictures.length <= 0) {
        steroids.layers.pop();
    }
};
4

1 回答 1

6

AppGyver 员工在这里!Steroids 中的 WebView 是独立的“浏览器”实例,每个实例都有自己的 DOM 和 JavaScript 运行时。我写了一个关于这个主题的快速指南,看看: http: //guides.appgyver.com/steroids/guides/steroids-js/sharing-data-between-webviews/

基本上,您需要确保inspectionService在不同视图之间保持状态 - 指南中关于使用背景 HTML WebView 的最后一节应该很有用!

于 2013-11-06T09:53:59.820 回答