我开发了一个Web控制面板,其中包含嵌入控件内部的控件结构.在许多情况下,我有一个控件的ID,需要处理实际的控件对象.因此,我使用一个实用方法,一个递归的FindControl实现,它搜索页面(或任何其他提供的对象,但我总是使用Page),作为控件的ID.
/// <summary>
/// Page.FindControl is not recursive by default.
/// </summary>
/// <param name="root"> Page </param>
/// <param name="id"> ID of control looking for. </param>
/// <returns> The control if found, else null. </returns>
public static Control FindControlRecursive(Control root, string id)
{
if (int.Equals(root.ID, id))
{
return root;
}
foreach (Control control in root.Controls)
{
Control foundControl = FindControlRecursive(control, id);
if (!object.Equals(foundControl,null))
{
return foundControl;
}
}
return null;
}
Run Code Online (Sandbox Code Playgroud)
此功能可以变得非常慢.一旦我把log4net登录到它,我意识到有多慢.我现在正试图尽可能地离开它,但我不知道我有什么其他选择,如果有的话.
例如,用户将控件拖放到我的网页上.事件处理程序如下所示:
protected void RadListBox_Dropped(object sender, RadListBoxDroppedEventArgs e)
{ …Run Code Online (Sandbox Code Playgroud) 随着时间的推移,我的课程一直在稳步增长.它被称为LayoutManager.
它开始是我跟踪我的页面上动态创建的控件的一种方式.所以,例如,我有这个:
public CormantRadDockZone()
{
ID = String.Format("RadDockZone_{0}", Guid.NewGuid().ToString().Replace('-', 'a'));
MinHeight = Unit.Percentage(100);
BorderWidth = 0;
HighlightedCssClass = "zoneDropOk";
CssClass = "rightRoundedCorners";
LayoutManager.Instance.RegisteredDockZones.Add(this);
}
Run Code Online (Sandbox Code Playgroud)
通过这种方式,在页面生命周期的开始阶段,将重新创建控件,并将它们添加到各自的控件列表中.
过了一会儿,我发现自己在方法之间传递'Page'对象.这只是为了能够访问页面上的控件.我心想 - 我已经有了布局管理器,我只会以同样的方式处理静态控件.
因此,我的Page_Init方法现在看起来像这个烂摊子:
protected void Page_Init(object sender, EventArgs e)
{
SessionRepository.Instance.EnsureAuthorized();
LayoutManager.Instance.RegisteredPanes.Clear();
LayoutManager.Instance.RegisteredDocks.Clear();
LayoutManager.Instance.RegisteredDockZones.Clear();
LayoutManager.Instance.RegisteredSplitters.Clear();
LayoutManager.Instance.RegisteredSplitBars.Clear();
LayoutManager.Instance.RegisteredPageViews.Clear();
LayoutManager.Instance.CheckBox1 = CheckBox1;
LayoutManager.Instance.CheckBox4 = CheckBox4;
LayoutManager.Instance.StartEditButton = StartEditButton;
LayoutManager.Instance.FinishEditButton = FinishEditButton;
LayoutManager.Instance.RadNumericTextBox1 = RadNumericTextBox1;
LayoutManager.Instance.RadNumericTextBox2 = RadNumericTextBox2;
LayoutManager.Instance.LeftPane = LeftPane;
LayoutManager.Instance.DashboardUpdatePanel = DashboardUpdatePanel;
LayoutManager.Instance.CustomReportsContainer = CustomReportsContainer;
LayoutManager.Instance.HistoricalReportsContainer = HistoricalReportsContainer;
RegenerationManager.Instance.RegenerateReportMenu();
LayoutManager.Instance.MultiPage = DashboardMultiPage;
LayoutManager.Instance.MultiPageUpdatePanel …Run Code Online (Sandbox Code Playgroud) 我有一个动态创建的HTML元素.它有一些CSS和HTML:
<div id="element"></div>
#element{
height: 200px;
width: 200px;
background-color: blue;
}
#element:hover{
cursor: pointer;
}
Run Code Online (Sandbox Code Playgroud)
然后,当鼠标仍然在元素上时,它将以编程方式从页面中删除.
$('#element').hover(function(){
setTimeout(function(){
$(this).remove();
}.bind(this), 1000);
});
Run Code Online (Sandbox Code Playgroud)
这使光标看起来像一个指针,直到鼠标移动.有什么办法可以解决这个问题,同时仍然使用CSS悬停?
这是一个小提琴:http://jsfiddle.net/mHdtU/
编辑:这是最新的谷歌浏览器.此外,显然HIDING元素会导致光标更新.光标未更新的事实是否删除了谷歌浏览器中的错误?
$('#element').hover(function(){
setTimeout(function(){
$(this).hide();
setTimeout($(this).remove.bind(this));
}.bind(this), 1000);
});
Run Code Online (Sandbox Code Playgroud) 我有一个绝对定位的元素,我正在转换到视口.元素中包含文本.我的理解是这样的:
将过渡应用于元素的位置(即顶部,左侧,底部,右侧,边距,填充)是不好的做法.这样做会强制浏览器在元素在页面上移动时重新流动.
将变换应用于元素是一种很好的做法,因为当模型位置保持在原始位置时,浏览器不会产生重新流动.
将转换应用于Webkit浏览器中的元素会强制进行硬件加速.(或者可以强制这样做,即如果转换:translateX没有那么你可以使用translate3d,z轴为0).
硬件加速的文本不被视为矢量.这会导致文本变得模糊.
我发现这篇文章讨论了解决方法,但我并不满意.
看起来使用变换转换元素会更好,但是,一旦元素到达其静止状态,用相同度量的左/顶部替换变换以从硬件加速中移除元素.
我是在正确的轨道上吗?这里有更简单的解决方案吗?
举个简单的例子,在切换will-change属性时查看文本.您可以看到,即使没有发生变换,文本也会在预期发生变换时模糊.这与在元素上完成移动/将文本放在移动元素旁边之后在元素上留下变换是一回事.告诉Chrome将文本保持为向量会非常好,但我怀疑所有父元素都会被提升,这就是文本被更改的原因.
$('button').click(function() {
$('.example').toggleClass('is-blurred');
});Run Code Online (Sandbox Code Playgroud)
.example {
font-size: 24px;
}
.example.is-blurred {
will-change: transform;
}Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button>Toggle blur</button>
<div class='example'>
I am some text
</div>Run Code Online (Sandbox Code Playgroud)
我有一个以空白/默认状态启动的仪表板.我让用户能够将已保存的状态加载到仪表板中.当他们单击"应用"按钮时,我运行以下代码:
function CloseAndSave() {
var radUpload = $find(radUpload1ID);
var inputs = radUpload.getFileInputs();
if (inputs[0].value.length == 0) {
alert('Please select a dashboard to upload.');
return;
}
if( !radUpload.isExtensionValid(inputs[0].value) ) {
alert('Please select an XML file.');
radUpload.clearFileInputAt(0);
return;
}
oWindow = null;
__doPostBack(radButton1ID);
}
protected void RadButton1_Click(object sender, EventArgs e)
{
if (RadUpload1.UploadedFiles.Count > 0)
{
UploadedFile dashboardXMLFile = RadUpload1.UploadedFiles[0];
SerializableDictionary<string, string> dataToLoad = new SerializableDictionary<string, string>();
XmlSerializer xmlSerializer = new XmlSerializer(dataToLoad.GetType());
using (StreamReader reader = new StreamReader(dashboardXMLFile.InputStream))
{
dataToLoad = (SerializableDictionary<string, …Run Code Online (Sandbox Code Playgroud) 我有一个帆布,可容纳中等到大量的形状(50-500).
我成功地使用这些工具绘制了我想要的形状轮廓:
function DrawPolygon(diagramLayer, polygon) {
var diagramImage = new Kinetic.Shape(function () {
var context = this.getContext();
context.beginPath();
context.lineWidth = 1;
context.strokeStyle = "#ff0000";
var lastVertice = polygon.Vertices[polygon.Vertices.length - 1];
context.moveTo(lastVertice.X, lastVertice.Y);
for (var i = 0; i < polygon.Vertices.length; i++) {
var vertice = polygon.Vertices[i];
context.lineTo(vertice.X, vertice.Y);
}
context.stroke();
context.closePath();
});
diagramImage.on("mouseover", function () {
});
diagramLayer.add(diagramImage);
planViewStage.add(diagramLayer);
}
Run Code Online (Sandbox Code Playgroud)
我想在mouseOver上将diagramImage的context的strokeStyle更改为不同的颜色.据我所知,canvas元素没有跟踪'state',因此,不知道它当前有一个形状.
我想知道一些事情:
有人可以向我解释一下吗?
var diagramImage = new Kinetic.Shape(function () {
var context = this.getContext();
context.beginPath();
context.lineWidth = 1;
//This is crazy tricks. It's part of the KineticJS demo website, but how am I able to assign diagramImage.color here?
context.strokeStyle = diagramImage.color;
var lastVertice = polygon.Vertices[polygon.Vertices.length - 1];
context.moveTo(lastVertice.X, lastVertice.Y);
for (var i = 0; i < polygon.Vertices.length; i++) {
var vertice = polygon.Vertices[i];
context.lineTo(vertice.X, vertice.Y);
}
context.stroke();
context.closePath();
});
Run Code Online (Sandbox Code Playgroud)
在我看来,diagramImage在Kinetic构造函数返回之前不存在,但我能够(并且似乎需要)在创建之前将上下文指定strokeStyle为diagramImage颜色diagramImage?为什么这样做?
编辑:完整代码:
function DrawPolygon(diagramLayer, polygon) …Run Code Online (Sandbox Code Playgroud) 我的问题的实质是:如果我向服务器发出$ .ajax请求以进行服务器端验证 - 我应该如何处理验证响应?我认为自己有两种选择:
// Server handled error:
$.ajax({
url: 'controller/action',
data: {},
success: function(response){
console.log("Error:", response.error);
}
}
// Server unhandled error:
$.ajax({
url: 'controller/action',
data: {},
success: function(){
},
error: function(error){
console.log("Error:", error);
}
}
Run Code Online (Sandbox Code Playgroud)
前一个示例假设我的服务器控制器有一个try/catch,它消耗任何服务器端异常.然后它接受任何异常并将它们作为json成功对象的一部分返回.后者允许服务器的异常冒泡并在ajax错误处理程序中捕获.
我个人认为我更喜欢后者.但是,我刚刚遇到远程问题 - 如果我们的服务器的安全设置没有放松,那么错误消息会被隐藏为'运行时错误',并且从ajax的onerror事件处理程序中读取错误信息变得不可能.
我想避免这个问题,我需要始终能够读取我的错误,但让我的ajax请求始终返回成功似乎是错误的.
这通常如何处理?
[HttpPost, AjaxOnly]
public ActionResult ChangePassword(ChangePasswordDialogModel model)
{
string error = string.Empty;
if (model.NewPassword == model.NewPasswordConfirm)
{
using (var service = new SecurityServicesSoapClient())
{
error = service.ChangePassword(SessionManager.Default.User.UserName, model.OldPassword,
model.NewPassword);
}
}
else
{
error = "New …Run Code Online (Sandbox Code Playgroud) 以下代码段显示了文本输入字段的两个示例.聚焦时,输入的底部厚度增加并改变颜色.
第一个示例使用border-bottom和box-shadow的组合来实现效果.第二个例子只使用box-shadow.我认为效果应该是相同的.但是,只有box-shadow示例在完成转换时才会"跳转".为什么?有没有办法改善它?
示例仅在Webkit的稳定版本上进行了测试.
input[type="text"] {
border-top: none;
border-left: none;
border-right: none;
padding: 0 0 8px 0;
transition: box-shadow 0.3s, border 0.3s;
will-change: box-shadow, border;
outline: none;
box-sizing: border-box;
}
#example1 {
border-bottom-width: 1px;
border-bottom-color: rgba(0, 0, 0, 0.26);
}
#example1:focus {
border-bottom-color: #2196F3;
box-shadow: inset 0 -1px 0 #2196F3;
}
#example2 {
border-bottom: none;
padding-bottom: 9px;
box-shadow: inset 0 -1px 0 rgba(0, 0, 0, .26);
}
#example2:focus {
box-shadow: inset 0 -2px 0 #2196F3;
}Run Code Online (Sandbox Code Playgroud)
<input type="text" id="example1" placeholder="I'm a …Run Code Online (Sandbox Code Playgroud)我有一个看起来像的对象:
const myObject = {
foo: '000',
bar: '123',
baz: '456'
};
Run Code Online (Sandbox Code Playgroud)
我想将一个myObject属性值的子集放入数组中.我需要保留订购.
手动解决方案如下:
const values = [myObject.foo, myObject.baz];
Run Code Online (Sandbox Code Playgroud)
一次尝试可能看起来像:
const values = _.values(_.pick(myObject, ['foo', 'baz']));
Run Code Online (Sandbox Code Playgroud)
此解决方案不正确,因为pick创建了一个新对象.调用_.values新对象将删除拾取数组中指定的顺序.
是否有一种简单的方法可以做到这一点?