在这里,我正在尝试在父项和子项上使用复选框的可折叠/树结构,但我无法准确地创建它,我能够从 json 创建直到无序列表
{
"properties": {
"host": {
"fields": {
"keyword": {
"ignore_above": 256,
"type": "keyword"
}
},
"type": "text",
"fielddata": true
},
"information": {
"properties": {
"filetype": {
"fields": {
"keyword": {
"ignore_above": 256,
"type": "keyword"
}
},
"type": "text",
"fielddata": true
},
"author": {
"fields": {
"keyword": {
"ignore_above": 256,
"type": "keyword"
}
},
"type": "text",
"fielddata": true
},
"authorcountry": {
"fields": {
"keyword": {
"ignore_above": 256,
"type": "keyword"
}
},
"type": "text",
"fielddata": true
}
}
},
"url": {
"fields": {
"keyword": {
"ignore_above": 256,
"type": "keyword"
}
},
"type": "text",
"fielddata": true
},
"name": {
"fields": {
"keyword": {
"ignore_above": 256,
"type": "keyword"
}
},
"type": "text",
"fielddata": true
},
"instrument": {
"properties": {
"Style": {
"fields": {
"keyword": {
"ignore_above": 256,
"type": "keyword"
}
},
"type": "text",
"fielddata": true
},
"instrumentCode": {
"type": "integer"
},
"instrumentName": {
"type": "text"
},
"instrumentNumber": {
"fields": {
"keyword": {
"ignore_above": 256,
"type": "keyword"
}
},
"type": "text",
"fielddata": true
}
}
}
}
}
.html代码
<button class="btn btn-primary" (click)="getData()">getData</button>
<h1>ul element</h1>
<hr>
<ul class="list-group" *ngFor="let x of inf | keyvalue">
<li class="list-group-item">{{x.key}}</li>
<ng-container *ngIf="x.value.hasOwnProperty('properties')">
<ul *ngFor="let y of x.value.properties | keyvalue">
<li>
{{y.key}}
</li>
</ul>
</ng-container>
</ul>
可折叠/树结构
下面是我的 stackblitz 链接
https://stackblitz.com/edit/angular-k5tdpe
我也可以尝试插件,但是插件的输入数据格式不同 angular2-tree plugin & ng2 -tree/ngx-tree 所以任何建议
最佳答案
只需添加一个输入类型检查并使用 [(ngModel)]
<ul class="list-group" *ngFor="let x of inf | keyvalue">
<li class="list-group-item">
<!--add a input type checkbox and relation with x.check-->
<input type="checkbox" [(ngModel)]="x.check">
{{x.key}}</li>
<!---change the *ngIf to add the x.check condition-->
<ng-container *ngIf="x.check && x.value.hasOwnProperty('properties')">
<ul *ngFor="let y of x.value.properties | keyvalue">
<li>
{{y.key}}
</li>
</ul>
</ng-container>
</ul>
已更新 如果你想要一个“递归组件”很容易。我举个例子,你可以在stackblitz中看到结果
基本上,“递归组件是模板中具有相同组件的组件。通常我们使用具有子属性的 json 模型(是的,您可以将“复杂”json 转换为具有子属性的一些模型)如果有一次你创建了一个带有 child 的 jsondata,你的 json 就像,例如
data = [{
title: "uno", children: [
{ title: "uno-uno" }]
},
{
title: "dos", children: [
{ title: "dos-uno",children: [
{ title: "dos-uno" }
]},
{ title: "dos-dos" }]
}
]
我们可以有一个像这样的 app.component
<li *ngFor="let item of data">
<app-li [title]="item.title" [children]="item.children"></app-li>
</li>
还有我们的app-li like
<li (click)="check=!check">
<div [className]="children?check?'arrow-down':'arrow-up':'arrow-right'"></div>
{{title}}
</li>
<ul *ngIf="children && check">
<ng-container *ngFor="let item of children">
<app-li [title]="item.title" [children]="item.children"></app-li>
</ng-container>
</ul>
看到我们用“ child ”喂养 app-li
注意:我添加了一个带有 className 的
更新 2
我们可以传递自己的项目本身 组件变成这样 还有应用@Component({
selector: 'app-li',
template: `<li >
<div (click)="check=!check" [className]="item.children?
check?'arrow-down':'arrow-up':'arrow-right'">
</div>
<input type="checkbox" [(ngModel)]="item.select" >
<span (click)="check=!check">{{item.title}}</span>
</li>
<ul *ngIf="item.children && check">
<ng-container *ngFor="let item of item.children">
<app-li [item]="item" ></app-li>
</ng-container>
</ul>
`,
styleUrls: [ './hello.component.css' ]
})
export class HelloComponent {
@Input() item: any;
}
<li *ngFor="let item of data">
<app-li [item]="item" ></app-li>
</li>
关于javascript - 如何使用angular 6和bootstrap 3.3.7创建带有复选框列表的可折叠/可展开/树结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53685156/
我想将html转换为纯文本。不过,我不想只删除标签,我想智能地保留尽可能多的格式。为插入换行符标签,检测段落并格式化它们等。输入非常简单,通常是格式良好的html(不是整个文档,只是一堆内容,通常没有anchor或图像)。我可以将几个正则表达式放在一起,让我达到80%,但我认为可能有一些现有的解决方案更智能。 最佳答案 首先,不要尝试为此使用正则表达式。很有可能你会想出一个脆弱/脆弱的解决方案,它会随着HTML的变化而崩溃,或者很难管理和维护。您可以使用Nokogiri快速解析HTML并提取文本:require'nokogiri'h
我有一个ModularSinatra应用程序,我正在尝试将Bootstrap添加到应用程序中。get'/bootstrap/application.css'doless:"bootstrap/bootstrap"end我在views/bootstrap中有所有less文件,包括bootstrap.less。我收到这个错误:Less::ParseErrorat/bootstrap/application.css'reset.less'wasn'tfound.Bootstrap.less的第一行是://CSSReset@import"reset.less";我尝试了所有不同的路径格式,但它
给定一个复杂的对象层次结构,幸运的是它不包含循环引用,我如何实现支持各种格式的序列化?我不是来讨论实际实现的。相反,我正在寻找可能会派上用场的设计模式提示。更准确地说:我正在使用Ruby,我想解析XML和JSON数据以构建复杂的对象层次结构。此外,应该可以将该层次结构序列化为JSON、XML和可能的HTML。我可以为此使用Builder模式吗?在任何提到的情况下,我都有某种结构化数据-无论是在内存中还是文本中-我想用它来构建其他东西。我认为将序列化逻辑与实际业务逻辑分开会很好,这样我以后就可以轻松支持多种XML格式。 最佳答案 我最
您将如何构建一个简单的Sinatra应用程序?我正在制作,我希望该应用具有以下功能:“应用程序”更像是一个包含所有信息的管理仪表板。然后另一个应用程序将通过REST访问信息。我还没有创建仪表板,只是从数据库中获取东西session和身份验证(尚未实现)您可以上传图片,其他应用可以显示这些图片我已经使用RSpec创建了一个测试文件通过Prawn生成报告目前的设置是这样的:app.rbtest_app.rb因为我实际上只有应用程序和测试文件。到目前为止,我已经将Datamapper用于ORM,将SQLite用于数据库。这是我的第一个Ruby/Sinatra项目,所以欢迎任何和所有建议-我应
我遇到了一个非常奇怪的问题,我很难解决。在我看来,我有一个与data-remote="true"和data-method="delete"的链接。当我单击该链接时,我可以看到对我的Rails服务器的DELETE请求。返回的JS代码会更改此链接的属性,其中包括href和data-method。再次单击此链接后,我的服务器收到了对新href的请求,但使用的是旧的data-method,即使我已将其从DELETE到POST(它仍然发送一个DELETE请求)。但是,如果我刷新页面,HTML与"new"HTML相同(随返回的JS发生变化),但它实际上发送了正确的请求类型。这就是这个问题令我困惑的
我想编写一个ruby脚本来递归复制目录结构,但排除某些文件类型。因此,给定以下目录结构:folder1folder2file1.txtfile2.txtfile3.csfile4.htmlfolder2folder3file4.dll我想复制这个结构,但不包含.txt和.cs文件。因此,生成的目录结构应如下所示:folder1folder2file4.htmlfolder2folder3file4.dll 最佳答案 您可以使用查找模块。这是一个代码片段:require"find"ignored_extensions=[".cs"
我有以下不起作用的代码:=form_for(resource,:as=>resource_name,:url=>session_path(resource_name),:html=>{:class=>"well"})do|f|=f.label:email=f.email_field:email=f.label:password=f.password_field:password-ifdevise_mapping.rememberable?%p=f.label:remember_me,:class=>"checkbox"=f.check_box:remember_me,:class=>"
我正在尝试消除使用Bootstrap3的Rails4元素中的glyphicon错误。我没有使用任何Bootstrapgem将其添加到Assets管道中。我手动将bootstrap.css和bootstrap.js添加到各自的app/assets目录下,分别添加到application.css和application.js什么的我现在在网络浏览器的控制台中看到以下内容:GEThttp://localhost:3000/fonts/glyphicons-halflings-regular.woff404(NotFound)localhost/:1GEThttp://localhost:30
对于我正在编写的Rails3应用程序,我正在考虑从本地文件系统上的XML、YAML或JSON文件中读取一些配置数据。重点是:我应该把这些文件放在哪里?Rails应用程序中是否有用于存储此类内容的默认位置?附带说明一下,我的应用程序部署在Heroku上。 最佳答案 我经常做的是:如果文件是通用配置文件:我在目录/config中创建一个YAML文件,每个环境有一个上层key如果我为每个环境(大项目)创建一个文件:我为每个环境创建一个YAML并将它们存储在/config/environments/然后我在加载YAML的地方创建了一个初始化
我有这个:AccountSummary我想单击该链接,但在使用link_to时出现错误。我试过:bot.click(page.link_with(:href=>/menu_home/))bot.click(page.link_with(:class=>'top_level_active'))bot.click(page.link_with(:href=>/AccountSummary/))我得到的错误是:NoMethodError:nil:NilClass的未定义方法“[]” 最佳答案 那是一个javascript链接。Mechan