小编Gre*_*ome的帖子

Angularjs - 如何在数组和本地存储中存储对象

我如何将多个对象存储到一个数组中,然后存储到本地存储中,这样我就可以在需要时使用循环获取所有对象.

示例对象:

var newMsg = {
      sentDate: msgDate,
      sentTime: msgTime,
      msgTitle: "message title",
      msgDesc: "message desc"
    };
Run Code Online (Sandbox Code Playgroud)

目前我正在使用https://github.com/grevory/angular-local-storage#configuration-example angularjs模块,但很难从数组中存储和检索对象.

我试过以下代码:

msgArray = [];
var savedMsgs = localStorageService.set("wimmtkey", newMsg);

    msgArray.push(savedMsgs); 
    console.log(savedMsgs);
Run Code Online (Sandbox Code Playgroud)

这在控制台中输出'true'但期望看到存储的对象.还请建议循环访问数组以检索对象.谢谢.

angularjs ionic-framework

6
推荐指数
1
解决办法
1万
查看次数

Angular JS - 将ng-click $ index值传递给控制器​​函数,然后返回另一个视图

我将ng-click $ index值传递给我的控制器,然后使用它在ng-repeat中的值来表示我的数据,但得到的错误表明"ReferenceError:myChoice未定义"

我的观点(months.html)有一个所有月份的列表,选中后,它会将值传递给控制器​​.

<ion-list ng-repeat="time in times.months" ng-click="getMonthId($index)" style="">
  <ion-item style="" href="#/dmtimes">{{ time.monthId }} - {{ time.MonthName }</ion-item>
</ion-list>
Run Code Online (Sandbox Code Playgroud)

视图输出显示:

1 - Jan
2 - Feb 
3 - Mar
etc
Run Code Online (Sandbox Code Playgroud)

我的控制器有以下提取代码:

.controller('dailyMeetingTimesCtrl', function($scope, MeetingNames, $ionicLoading, $firebase, $firebaseArray) {

  $scope.getMonthId = function (monthId) {
    alert("you selected: " + monthId); // this works fine.
    $scope.myChoice = monthId; // ReferenceError: myChoice is not defined

    console.log(myChoice);
  }
})
Run Code Online (Sandbox Code Playgroud)

在我的第二个视图(displayMeetingTimes.html)中,我想显示所选月份的会议详细信息,时间等.代码如下:

<ion-view title="Daily Meeting Times">
  <ion-content ng-controller="dailyMeetingTimesCtrl" class="has-header" overflow-scroll="true" padding="true">
    <ion-list>

      <ion-item ng-repeat="time in times.months(myChoice).days" …
Run Code Online (Sandbox Code Playgroud)

angularjs ionic

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

angularjs ×2

ionic ×1

ionic-framework ×1