我正在使用 Appgyver Steroids 和 AngularJs 开发一个 HTML5 移动应用程序。 该应用程序使用全局 javascript 对象来填充步骤中的信息,并由整个应用程序使用。 一切都很好,直到我需要创建一个 gallery.html 并将其作为 Web 层从我的主 Controller 推送。 main.html 和 gallery.html 有自己的 Controller 。 Gallery.html 按预期从 javascript 对象显示所有图片,当我删除它们时,它们也按预期从 javascript 对象中删除。 但是,当我返回 main.html 并单击“画廊”时,它们又都出现在 gallery.html 中。
我认为一定存在范围问题或多个实例的问题?如何让 gallery.html 读取实际对象(所有被删除后没有图片的对象)?为什么 gallery.html 不更新它的值?我一直在运行代码,它没有任何问题,但是当我在 web 层中使用它时,会发生这种情况。
在主 Controller 中:
$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();
}
};
在图库 Controller 中:
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();
}
};
最佳答案
AppGyver 员工在这里! Steroids 中的 WebView 是独立的“浏览器”实例,每个实例都有自己的 DOM 和 JavaScript 运行时。我写了一个关于这个主题的快速指南,查看:http://guides.appgyver.com/steroids/guides/steroids-js/sharing-data-between-webviews/
基本上,您需要确保在不同的 View 之间保持inspectionService
状态——指南中关于使用后台 HTML WebView 的最后一节应该很有用!
关于javascript - Appgyver 类固醇,Web View 中的更新对象不会显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19799221/