我正在学习 AngularJS,并且正在开发一个应用程序,其中有问题和答案。

问题使用递增的方式 +- 每个项目的按钮更新 $scope

不过,我想知道的是,因为我必须在答案中访问应用程序问题端的值,所以最简单的方法是什么?我曾想过将 $scope.questions 存储到本地存储中。

{
    "uid" : 1,
    "name": "Quiz",
    "drinks" : [
        {
            "id" : 0,
            "type" : "Footballs",
            "image" : "http://placehold.it/280x300",
            "amount" : ""
        },
        {
            "id" : 1,
            "type" : "Golf Balls",
            "image" : "http://placehold.it/280x300",
            "amount" : ""
        }
]
}

上面是 json,它被输入到我的页面中,然后使用 ng-repeat 它将显示,然后 amount 当用户单击任一键时,键都会更新 + 或者 -.

我想以某种方式更新此 json,以便在整个站点中也可访问,以便当用户/客户端更新它时,他们可以查看一个单独的页面,其中显示了答案。

有帮助吗?

解决方案

用过的 localStorage 携带来自 $scope 的数据

localStorage.setItem('data', angular.toJson($scope.data));
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top