会话cookie对象数组变成对象

时间:2019-01-03 19:23:23

标签: javascript jquery session-cookies

我所有的数组项目都变成了对象类型

我已将Session Cookie与javascript一起使用(您可以看到here),并获得具有类not-seen的元素,并返回到Session对象中

var notiCookie = Session.get("notiCookie") || {
  length: 0,
  class: "not-seen",
  element: []
};
$.getJSON("/feeds/posts/summary?alt=json", function(data) {
  // Get Label List
  $(data.feed.category).each(function(key, value) {
    var cat = value.term;
    $.ajax({
      type: "GET",
      url: "/feeds/posts/summary/-/" + cat,
      data: {
        "alt": "json",
        "max-results": 1
      },
      dataType: "jsonp",
      success: function(data) {
        var item = "";
        $(data.feed.entry).each(function(i) {
          for (
            var j = 0, entry = data.feed.entry[i], leng = entry.link.length;
            j < leng;
            j++
          ) {
            if (entry.link[j].rel === "alternate") {
              var link = entry.link[j].href;
              break;
            }
          }
          item +=
            "<div class='noti_item new_post not-seen'><a target='_blank' href='" +
            link +
            "'>Có bài viết mới tại chuyên mục <b>" +
            cat +
            "</b>! click để xem ngay !</a></div>";
        });
        $("#notification").append(item);
      }
    }).done(function() {
      var notiwrap = document.getElementById("notification");
      var noti_count = (notiCookie.length = $("#notification").find(
        ".noti_item"
      ).length);
      var items = notiwrap.getElementsByClassName("noti_item");
      for (var i = 0, len = items.length; i < len; i++) {
        var elements = items[i];
        elements.addEventListener("click", function(e) {
          if (this.classList.contains("not-seen")) {
            this.classList.remove("not-seen");
            this.classList.add("seen");
          }
          notiCookie.element = Array.prototype.slice.call(
            document.getElementsByClassName("not-seen")
          );
          Session.set("notiCookie", notiCookie);
        });
      }
      console.log(notiCookie.element);
    });
  });
});

我想获取notiCookie对象内部的数组的值

0 个答案:

没有答案