小编pra*_*ram的帖子

AngularJS'scrollTop'相当于什么?

我想在AngularJS指令中实现类似的东西:

https://github.com/geniuscarrier/scrollToTop/blob/master/jquery.scrollToTop.js

这是相当简单的,当你不在页面的顶部时,它将淡入按钮滚动到顶部:

 $(window).scroll(function() {
                if ($(this).scrollTop() > 100) {
                    $this.fadeIn();
                } else {
                    $this.fadeOut();
                }
            });
Run Code Online (Sandbox Code Playgroud)

但是我很难找到如何在Angular中获取当前滚动位置.我宁愿不必仅仅为这件事使用jQuery.

谢谢!

javascript angularjs angularjs-directive

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

在Go中编码嵌套的JSON

找到一个这样的例子我遇到了很多麻烦.互联网上的大多数信息都是关于解码JSON的.

我想将一些数据序列化为嵌套的JSON,例如:

{
  "item": {
      "title": "Items",
    "properties": [
      {
        "num": 1,
        "name": "Item 1"
      },
      {
        "num": 2,
        "name": "Item 2"
      }
    ]
  }
}
Run Code Online (Sandbox Code Playgroud)

我知道如何使用平面结构编组数据,但是如何将数据放入可以使用嵌套序列化的结构中?

http://play.golang.org/p/nDKmv1myTD

我发现这个工具从JSON模式生成结构,但我不明白如何将数据导入子结构.

http://mholt.github.io/json-to-go/

type Example struct {
    Item struct {
        Title string `json:"title"`
        Properties []struct {
            Num int `json:"num"`
            Name string `json:"name"`
        } `json:"properties"`
    } `json:"item"`
}
Run Code Online (Sandbox Code Playgroud)

encoding serialization json go

3
推荐指数
1
解决办法
1083
查看次数