小编bnu*_*sey的帖子

Angular2订阅Child Component中对@Input的更改

我有一个父子组件.父组件具有index并将其传递给子组件作为@Input.这个index值在父组件中不断变化,在我的子组件中,我希望每次父组件更改时都运行一个函数index.这有一个不断更改它的幻灯片组件.我怎样才能做到这一点?我已尝试使用下面的代码(this.index.subscribe(() =>),但我发现每次尝试初始化订阅时它都不是函数.

编辑:Child模板中没有可能影响此的相关代码,因此未提供.ngOnChange似乎不起作用,因为指令发生了变化,而不是parent模板.

儿童:

import {Component, OnInit, ViewChild, Input} from '@angular/core';
import {Observable} from 'rxjs/Observable';

@Component({
    selector: "child",
    templateUrl: "components/child/child.html",
})

export class ChildComponent implements OnInit {
    @Input() index: string;
    currentIndex: any;

    constructor() {}

    ngOnInit() {}

    ngOnChanges(){}

    ngAfterViewInit() {
        console.log("index " + this.index);
        this.currentIndex = this.index.subscribe(() => {
             console.log("index " + this.index);
        })
    }

    ngOnDestroy() {
        this.currentIndex.unsubscribe();
    }

}
Run Code Online (Sandbox Code Playgroud)

家长:

import {Component, ElementRef, OnInit, …
Run Code Online (Sandbox Code Playgroud)

angular

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

根据多个列删除重复记录

在我们的系统中,我们从外部数据库运行每小时导入.由于导入脚本中的错误,现在存在一些重复记录.

如果任何记录具有相同的:legacy_id和,则认为副本:company.

我可以运行哪些代码来查找和删除这些重复项?

我正在玩这个:

Product.select(:legacy_id,:company).group(:legacy_id,:company).having("count(*) > 1")
Run Code Online (Sandbox Code Playgroud)

它似乎返回了一些副本,但我不确定如何从那里删除?

有任何想法吗?

sql activerecord ruby-on-rails duplicates rails-activerecord

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

如何创建自定义Scrapy项目导出器?

我正在尝试基于JsonLinesItemExporter创建一个自定义Scrapy项目导出器,这样我可以稍微改变它产生的结构.

我在这里阅读了http://doc.scrapy.org/en/latest/topics/exporters.html上的文档,但它没有说明如何创建自定义导出器,存储位置或如何将其链接到管道.

我已经确定了如何使用Feed Exporters进行自定义,但这不符合我的要求,因为我想从我的管道中调用此导出器.

这是我提出的代码,它存储在项目根目录中的一个文件中 exporters.py


from scrapy.contrib.exporter import JsonLinesItemExporter

class FanItemExporter(JsonLinesItemExporter):

    def __init__(self, file, **kwargs):
        self._configure(kwargs, dont_fail=True)
        self.file = file
        self.encoder = ScrapyJSONEncoder(**kwargs)
        self.first_item = True

    def start_exporting(self):
        self.file.write("""{
            'product': [""")

    def finish_exporting(self):
        self.file.write("]}")

    def export_item(self, item):
        if self.first_item:
            self.first_item = False
        else:
            self.file.write(',\n')
        itemdict = dict(self._get_serialized_fields(item))
        self.file.write(self.encoder.encode(itemdict))
Run Code Online (Sandbox Code Playgroud)

我只是尝试通过使用FanItemExporter并尝试导入的变体来从我的管道中调用它,但它不会产生任何结果.

python json scrapy

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

在 Active Admin 中显示来自两个或多个模型(具有相同数据结构)的数据

我们正在使用 Active Admin 和 Rails 构建一个应用程序。它有一系列具有相同数据结构的模型。

我们现在想要一个视图,将这些模型中的所有数据一起显示在一个表中。

分成许多模型的原因是它们都来自不同的来源。

所以作为管理员我想一起查看所有数据。

该数据是只读的,因此无需写入。

使用下面的代码,我能够将所有数据与自定义页面一起呈现,但这并没有利用 ActiveAdmin 内置的表呈现,因此毫无意义。请参阅下面的屏幕截图和使用的代码。

当前代码的屏幕截图

ActiveAdmin.register_page "Top Sellers" do
    content do
        table_for @items = Dingoat.all + Dingobe.all do
            column "Product Name", :ProductName
            column "Start Date", :StartDate
            column "End Date", :EndDate
        end

    end

end
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails activeadmin

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

编号ActiveAdmin报告中的项目

是否可以获取ActiveAdmin中每个项目的序列号?

所以它看起来像这样:

| Number | Name  |

| 1      | Bill  |

| 2      | Smith |  
Run Code Online (Sandbox Code Playgroud)

我知道这可以实现,each_with_index但不认为有一种方法可以使用ActiveAdmin.

可以添加一些东西controller do吗?

我想将此功能添加到ActiveAdmin的索引中,例如

index do
   column "Number" do |a|
       # Some way of specifying index number         
   end
   column "Name" do |a|
       a.name
   end

end
Run Code Online (Sandbox Code Playgroud)

谢谢

activeadmin

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