我有以下JSON,我想保持数组的格式相同,但只包含类型的对象"ar".如何使用JavaScript过滤此JSON以仅包含我需要的类型?
[{"time":"2016-07-26 09:02:27","type":"aa"},
{"time":"2016-04-21 20:35:07","type":"ae"},
{"time":"2016-08-20 03:31:57","type":"ar"},
{"time":"2017-01-19 22:58:06","type":"ae"},
{"time":"2016-08-28 10:19:27","type":"ae"},
{"time":"2016-12-06 10:36:22","type":"ar"},
{"time":"2016-07-09 12:14:03","type":"ar"},
{"time":"2016-10-25 05:05:37","type":"ae"},
{"time":"2016-06-05 07:57:18","type":"ae"},
{"time":"2016-10-08 22:03:03","type":"aa"},
{"time":"2016-08-13 21:27:37","type":"ae"},
{"time":"2016-04-09 07:36:16","type":"ar"},
{"time":"2016-12-30 17:20:08","type":"aa"},
{"time":"2016-03-11 17:31:46","type":"aa"},
{"time":"2016-05-04 14:08:25","type":"ar"},
{"time":"2016-11-29 05:21:02","type":"ar"},
{"time":"2016-03-08 05:46:01","type":"ar"},
]
Run Code Online (Sandbox Code Playgroud) 我有一个父组件,我想在其中创建和存储我的反应式表单。表单数组中将有多个表单组实例。我想将表单控件从每个表单组传递给子组件,但是在弄清楚如何做到这一点时遇到了麻烦。
这是一个Stackblitz,演示了我想做的事。另外,某些字段仅适用于汽车的某些“品牌”,这就是为什么我的html中包含以下行:
<input type="text" *ngIf="car.make != 'ford'" formControlName="model">
Run Code Online (Sandbox Code Playgroud)
我想将“详细信息”表单组字段移到“详细信息字段”子组件中,但是当我尝试这样做时,它告诉我我没有表单组实例,所以我知道父表单组是未在子组件中注册。任何帮助深表感谢。
components angular-components angular angular-reactive-forms angular-forms
在某些情况下,我只需要在模板中重复一些 html 代码来干燥它,但是制作一个新组件并向其传递大量的 props 和动态数据似乎有点矫枉过正。有没有办法定义可以重复使用的可重复模板代码块?
一个很好的例子是我error重复的 vuelidate 验证消息。我不想为它们创建一个完整的 vue 组件,因为这样我需要传递验证、validation prop 和其他一些东西,这样看起来就只是为了干燥一点模板而创建更多的复杂性。
我在同一模板中的三个不同场景中有这段代码,有没有办法可以将它们定义为block重用。从字面上看,没有任何改变,因此这非常违反 DRY 原则。
<span
v-if="!$v.initialReplyText.required"
class="error">Your reply cannot be empty.</span>
<span
v-if="!$v.initialReplyText.maxLength"
class="error">Your reply cannot be over 2,000 characters.</span>
Run Code Online (Sandbox Code Playgroud) 我有以下html:
<div class="balance">
<div class="heading">
<p class="total"><span>00</span></p>
</div>
<div class="instance withdrawal">
<h3>Random</h3>
<p>desc</p>
<p class="amount">$350.<span>00</span></p>
</div>
<div class="instance deposit">
<h3>Added in</h3>
<p>desc</p>
<p class="amount">$1,250.<span>00</span></p>
</div>
<div class="instance withdrawal">
<h3>Bill</h3>
<p>desc</p>
<p class="amount">$50.<span>00</span></p>
</div>
</div>
<!--end wallet-container left-->
Run Code Online (Sandbox Code Playgroud)
我如何使用jQuery添加总存款,减去提款并将其附加到p.total?
我只想在单击子组件中的按钮时更新父组件中的布尔值。我有一个基于动态 ngClass 隐藏和显示的滑出式子组件。该类是根据父级的布尔值设置的。但是,当我从子项中的按钮关闭该组件时,我想更新父项中的布尔值:
父组件打字稿:
export class AppComponent implements OnInit {
showFlyout: boolean
constructor() {}
ngOnInit() {
this.showFlyout = false;
}
}
Run Code Online (Sandbox Code Playgroud)
和父 html:
<main>
<button (click)="showFlyout = !showFlyout"><i class="fa fa-check"></i>Show Flyout</button>
{{showFlyout}}
<app-child id="flyout" [ngClass]="showFlyout ? 'active' : ''"></app-child>
</main>
Run Code Online (Sandbox Code Playgroud)
子组件打字稿:
export class ActivateFlyoutComponent implements OnInit {
constructor() { }
ngOnInit() {
}
closeActivationFlyout() {
const flyout = document.getElementById('flyout');
flyout.classList.remove('active');
}
}
Run Code Online (Sandbox Code Playgroud)
和子组件html:
<button (click)="closeFlyout()">Close</button>
Run Code Online (Sandbox Code Playgroud)
这是一个Stackblitz。您可以看到单击父按钮正确切换类,但是如何从子组件中的单击更新该布尔值,从而使子组件中的 closeActivationFlyout() 方法变得不必要?
我正在使用D3.js动态创建svg元素。单击圆圈时,将运行以下功能:
.on("click", function(d) {
d3.select(this).select("rect").transition().duration(900).style("visibility", "visible");
d3.select(this).selectAll("tspan").transition().duration(900).style("visibility", "visible");
})
Run Code Online (Sandbox Code Playgroud)
除了我的过渡效果不佳之外,单击圆圈显示圆圈的孩子为矩形和tspan,一切都很好。但是,如果单击另一个圆圈,则会显示新的矩形和tspan,但我需要隐藏当前的一个。想知道哪种最佳/最有效的方法是D3
我认为我目前写的是非常好的javascript,但我正试图采用更加面向对象的方法.我刚刚开始这样,请原谅我的诺言.我正在将我的一些功能移到对象上并遇到了这个问题.以前,我有一个像这样工作的手风琴功能:
jQuery(document).ready(function ($){
var accordionTrigger = $('.accordion-title');
function toggleAccordion() {
// Set a variable for the accordion content
var accordionContent = $('.accordion-container .accordion-content p');
// Slide up any open content
accordionContent.slideUp();
// Remove any active classes
accordionTrigger.removeClass("active");
// If the sibling content is hidden
if(!$(this).siblings().is(":visible")) {
// slide it down
$(this).siblings().slideDown();
// add a class to the title so we can style the active state and change the svg
$(this).addClass("active");
}
}
accordionTrigger.on("click", toggleAccordion);
});
Run Code Online (Sandbox Code Playgroud)
我把这个移到了我的新设置中的一个Object,如下所示:
Accordion = {
accordionContent: …Run Code Online (Sandbox Code Playgroud) 我有点绑定,需要一些帮助我将svg元素与CSV文件中包含的URL链接起来.我有一个超过100个符号的符号图.符号基于CSV文件中从经度和纬度中提取的坐标,该文件还包含我希望每个唯一符号链接到的链接.我知道有一种简单的方法可以做到这一点,我确信我忽略了解决方案.
我的CSV文件如下:
name,longitude,latitude,city,state,url
Run Code Online (Sandbox Code Playgroud)
查尔斯顿学院,803,342,查尔斯顿,SC,http: //sitename.com/colleges/college-of-charleston/
等等...
我的符号是使用D3生成的,并放置在我的SVG地图之上.我也使用D3将符号包装在锚标签中.我只是希望这些锚标签链接到与该特定符号的纬度和经度相关的适当URL.
/* Start SVG */
var width = 960,
height = 640.4,
positions = [],
centered;
var bodyNode = d3.select('#Map').node();
var list = $('.school-list').each(function(i){});
var svg = d3.select("#Map");
var contain = d3.select("#map-contain");
var circles = svg.append("svg:g")
.attr("id", "circles");
var g = d3.selectAll("g");
// var locationBySchools = {};
d3.csv("http://sitename.com/wp-content/themes/vibe/homepage/schools.csv",function(schools){
schools = schools.filter(function(schools){
var location = [+schools.longitude, +schools.latitude];
// locationBySchools[schools.loc] = location;
positions.push(location);
return true;
});
circles.selectAll("circles")
.data(schools)
.enter().append("svg:a")
.attr("xlink:href", function(d) { })
.append("svg:circle")
.attr("cx", …Run Code Online (Sandbox Code Playgroud) 有没有办法检测用户是否退出全屏视频.如果退出全屏模式,我想重新加载我的视频.我在这里找到了一些关于cancelFullScreen和exitFullScreen的内容,但我找不到任何东西对我有用.任何信息将不胜感激.
我有一个数组,如:
[16, 20, 1, 4, 6, 8, 9, 22, 18, 14, 13, 12]
Run Code Online (Sandbox Code Playgroud)
我希望根据范围1-4,5-8,9-12,13-16,17-20,21-24分成6个不同的阵列.
使用javascript执行此操作的最简单方法是什么?