我正在尝试将 Google 自定义搜索添加到我的 angular 2 应用程序中。当我将自定义搜索中的代码放入jsfiddle 时,使用自定义搜索中的代码可以工作,但是在将其插入到我的组件中时遇到问题。
问题似乎是,当插入脚本的代码运行时,html 标签<gcse:search>被剥离了它的gcse:一部分<search>,我猜运行的脚本找不到任何可以处理的元素。
My.component.html 本质上是:
<gcse:search></gcse:search>
Run Code Online (Sandbox Code Playgroud)
在 My.component.html.ts 我有一个实现 ngOnInit 的函数
ngOnInit(){
var cx = '016820916711928902111:qw0kgpuhihm';
var gcse = document.createElement('script');
gcse.type = 'text/javascript';
gcse.async = true;
gcse.src = 'https://cse.google.com/cse.js?cx=' + cx;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(gcse, s);
}
Run Code Online (Sandbox Code Playgroud) 我最近开始在Visual Studio 2015中使用mvc6和knockoutJS.当我在我的打字稿文件中使用knockout时,我在所有相关的jquery或knockout(或任何库)上得到红色下划线,并Cannot find name 'ko'在我的错误列表中说明.我知道IDE无法解决这些javascript对象确实存在的问题,但这肯定是每个人都有的问题吗?
如何从我的javascript/typescript文件中删除intellisense?
我们最近在我们的项目中更新了一堆dll,包括HtmlAgilityPack到他们的最新版本.这使得以下代码开始在第一行开始抛出错误.
List<HtmlNode> foundNodes = document.QuerySelectorAll(".divider").ToList();
foreach(HtmlNode node in foundNodes){
doWhatever(node);
}
Run Code Online (Sandbox Code Playgroud)
找不到方法:'System.Collections.Generic.IEnumerable`1 HtmlAgilityPack.HtmlNode.Descendants()'.
堆栈跟踪的最后一行是:
" 在Fizzler.Systems.HtmlAgilityPack.HtmlNodeOps.b__71(HtmlNode n) "
QuerySelectorAll返回一个IEnumerable的HtmlNode,但我似乎无法再将其强制转换为列表.我会冒险猜测现在有一些相关的dll与不兼容的版本(fizzler?)错过了这个Descendants方法?然而,HtmlAgilityPack 的NuGet页面没有显示任何依赖关系,我使用的fizzler版本是1.0.0,我认为是正确的.
我正在尝试构建一个多选组件,它可以为每个选择选项元素采用一个模板。它主要工作,模板是从选项组件中的 ng-content 中抓取的,并显示在“选择弹出窗口”中。
尝试在选择组件中显示所选选项时遇到问题。似乎模板一次只能在一个地方显示,因此当在“选择”中显示所选选项时,它将从POPOVER中删除。
有什么办法可以克隆 TemplateRef 组件吗?我实际上并不介意模板的上下文是否更新,因为我目前没有使用它的任何内容,只是模板。
为了清楚起见,包括下面的一些代码片段,我认为这没关系。
用途somepage.component.html:
<my-select [(value)]="vals">
<my-option *ngFor="let x of [1,2,3]" [value]="x">Option {{x}}</my-option>
</my-select>`
Run Code Online (Sandbox Code Playgroud)
我的选择.component.html
...
<ng-container [ngTemplateOutlet]="getSelectedOptionTemplate()"></ng-container>
...
Run Code Online (Sandbox Code Playgroud)
我的select.component.ts
getSelectedOptionTemplate(){
// Some way to clone here could solve the issue?
return this.getSelectedOption().template;
}
Run Code Online (Sandbox Code Playgroud)
my-select-overlay.component.html
...
<ng-container *ngFor="let opt of options;">
<ng-container [ngTemplateOutlet]="getTemplate(opt)"></ng-container>
</ng-container>
...
Run Code Online (Sandbox Code Playgroud)
my-option.component.html
<ng-template>
<ng-content></ng-content>
</ng-template>
Run Code Online (Sandbox Code Playgroud)
my-option.component.ts
...
@ViewChild(TemplateRef)
template: TemplateRef<any>;
...
Run Code Online (Sandbox Code Playgroud) 我在 blazor 中有一个列表组件,其中有一个可折叠的创建部分,我希望当您单击以显示创建部分时,它将显示并滚动到创建部分。我的问题是 StateHasChanged() 没有及时更新 UI,因此当 javascript 触发时,我们尝试滚动到的元素还不存在。
显然我可以通过超时来解决这个问题,但是在 Blazor 中执行此操作的更干净的方法是什么?有没有办法说类似await StateUpdated()......
我的代码看起来像这样:
@page "/createlist"
<div>
<h3>My List</h3>
<a @onclick="ToggleAdding">
Create New
</a>
</div>
<ul>
@* list existing items... *@
</ul>
@if (IsAdding)
{
<div id="some-create-id">
<h3>Add Section</h3>
@* create controls here *@
</div>
}
@code {
public void ToggleAdding()
{
IsAdding = !IsAdding;
// Need something similar to StateHasChanged(), that is awaitable.
JsRuntime.InvokeVoidAsync("ScrollIn", new object[] { CreateElementId });
}
}
Run Code Online (Sandbox Code Playgroud)
js 很简单:
ScrollIn = id => { …Run Code Online (Sandbox Code Playgroud) 我有一个 System.Windows.Forms.ListView 包含许多项目。它闪烁得令人无法忍受(似乎经常是这种情况),所以经过一番搜索后,我决定在“ListViewLessFlicker”类中做这两件事。
this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.Opaque, true);
Run Code Online (Sandbox Code Playgroud)
尽管 DoubleBuffering 在这些主题中最常作为解决方案给出,但它并没有太大影响,但将样式设置为不透明,真正大大减少了闪烁。
http://www.virtualdub.org/blog/pivot/entry.php?id=273
然而,它有一个副作用,我似乎无法找到解决办法。当我将鼠标悬停在 ListView 中的一个项目上时,它现在使文本变得粗体且非常模糊(除非 opaque 为真,否则不会发生这种情况)。
这是一个非常放大的示例。

如果有人有修复方法或知道为什么会这样做,我很想知道!
有5个没有.按钮(图像).最初都是关闭图像.一次只能打开1个.所以,当我按下img的src变为on.png的任何按钮时.然后,当我按下任何打开或关闭按钮时,按下的按钮源img变为on.png,而img上的所有其他按钮也变为off.png.
HTML代码是,
<table cellspacing="0" style="padding:0%; margin:0% auto;">
<tr><td><img id="img1" src="off.png" height="30" width="30" onclick="off(this.id);" /></td><td>45:78</td></tr>
<tr><td><img id="img2" src="off.png" height="30" width="30" onclick="off(this.id);" /></td><td>45:78</td></tr>
<tr><td><img id="img3" src="off.png" height="30" width="30" onclick="off(this.id);" /></td><td>45:78</td></tr>
<tr><td><img id="img4" src="off.png" height="30" width="30" onclick="off(this.id);" /></td><td>45:78</td></tr>
<tr><td><img id="img5" src="off.png" height="30" width="30" onclick="off(this.id);" /></td><td>45:78</td></tr>
</table>
Run Code Online (Sandbox Code Playgroud)
javascript代码是,
function off(a)
{
var images = document.getElementsByTagName('img');
for(var i = 0; i < images.length; i++)
{
var img = images[i];
alert(img.src);
if(img.src == 'on.png')
{
img.src = 'off.png';
}
}
document.getElementById(a).src='on.png';
}
Run Code Online (Sandbox Code Playgroud)
if()条件不起作用,请提供解决方案并解释其原因
工作.谢谢!