小编acc*_*cme的帖子

Array(2)和[undefined,undefined]之间有什么区别?

[undefined, undefined, undefined].map(function(val, i) { return i });
Run Code Online (Sandbox Code Playgroud)

返回[0,1,2],而

Array(3).map(function(val, i) { return i });
Run Code Online (Sandbox Code Playgroud)

返回[undefined,undefined,undefined].

为什么?

javascript arrays

14
推荐指数
1
解决办法
225
查看次数

为什么"typeof +''"返回"数字"?

让我们尝试在控制台中键入以下代码:

typeof + ''
Run Code Online (Sandbox Code Playgroud)

这将返回'number',而typeof本身没有参数会引发错误.为什么?

javascript

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

块内的绝对定位div,位置:固定和滚动条

我有一个div position: fixed,其中包含两个其他div:一个带内容,另一个必须始终位于主div的底部.

这是一个例子:

.scroller {
  position: fixed;
  border: 1px solid #ddd;
  width: 240px;
  height: 100px;
  top: 0;
  bottom: 0;
  overflow: auto;
}
.footer {
  position: absolute;
  bottom: 0;
}
Run Code Online (Sandbox Code Playgroud)
<div class="scroller">
  <div class="content">
    <div>content</div><div>content</div><div>content</div><div>content</div>
    <div>content</div><div>content</div><div>content</div><div>content</div>
    <div>content</div><div>content</div><div>content</div><div>content</div>
  </div>
  <div class="footer">FOOTER</div>
</div>
Run Code Online (Sandbox Code Playgroud)

问题是当用户滚动主块的内容时,页脚开始与其他内容一起移动,尽管位置:页脚块的绝对值.

有没有办法在不更改html结构的情况下将页脚粘贴到主固定块的底部?

如果主要div包含许多孩子,并且只有最后一个是我们需要坚持到底部的页脚呢?例:

.scroller {
  position: fixed;
  border: 1px solid #ddd;
  width: 240px;
  height: 100px;
  top: 0;
  bottom: 0;
  overflow: auto;
}
.footer {
  position: absolute;
  bottom: 0;
}
Run Code Online (Sandbox Code Playgroud)
<div class="scroller">
  <div class="content">
    <div>content</div><div>content</div><div>content</div><div>content</div>
  </div>
  <div class="content">
    <div>content</div><div>content</div><div>content</div><div>content</div> …
Run Code Online (Sandbox Code Playgroud)

css scroll css-position

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

Django中的复杂查询

也许是一个简单的问题,但我刚刚开始使用Django几年的PHP经验:-)

问题:我们有一对模型 - "类别"和"发布"."类别"是帖子类别的嵌套集树,"帖子"是带有ForeignKey字段的博客帖子的简单列表,链接到类别模型.这是一个例子:

class Categories(NS_Node):

    title = models.CharField(max_length = 150)
    slug = models.SlugField(unique = True)

class Post(models.Model):

    title = models.CharField(max_length = 150)
    slug = models.SlugField(unique = True)
    text = models.TextField()
    category = models.ForeignKey(Categories)
Run Code Online (Sandbox Code Playgroud)

NS_Node - 来自treebeard库的类,实现嵌套集数据模型.

用户可以通过访问带有"/ books/sci-fi /"等网址的页面查看指定类别的帖子.在名为"category"的django视图中,我们只需要选择链接到"sci-fi"类别的帖子.现在我这样做:

def category(request, path):

    # 'path' is 'books/sci-fi'
    # detect current category code from url
    category_slug = path.split('/')[-1]

    # get current category object
    category = Categories.objects.get(slug = category_slug)

    # get child categories
    childs = category.get_descendants();

    # make list of id for …
Run Code Online (Sandbox Code Playgroud)

django django-models

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

标签 统计

javascript ×2

arrays ×1

css ×1

css-position ×1

django ×1

django-models ×1

scroll ×1