我有一个要求,我可以在一个对象中获得以下内容 -
a type T or List<T>
Run Code Online (Sandbox Code Playgroud)
将对象转换为T很容易.如何将其转换为List(通过首先检查它是否可以成功转换),我想要转换的原因是滚动列表并在每个元素上调用tostring.
我的实际代码 -
namespace Generic_Collection_Code
{
class Program
{
public static string DumpObj(object obj)
{
string sTemp = String.Empty;
List<int> ints = obj as List<int>;
if (ints != null)
{
foreach (int i in ints)
sTemp += i.ToString() + ",";
sTemp.Trim(',');
}
else
{
List<string> strings = obj as List<string>;
if (strings != null)
{
foreach (string s in strings)
sTemp += s + ",";
sTemp.Trim(',');
}
else
{
sTemp += obj.ToString();
} …Run Code Online (Sandbox Code Playgroud) 我一直在使用MVC 2,似乎在某些时候,ModelBindingContext.ValueProvider类已被删除并替换为IValueProvider.因为这样我在迭代ValueProvider.Keys时遇到了麻烦.这是一个示例,我从代码中收到的消息已完成
private void foo(ModelBindingContext myMBC)
{
var myImportantKeys = myMBC.ValueProvider.Keys.where(keyValue => keyValue.StartsWith("important", StringComparison.InvariantCulture);
foreach(var importantKey in myImportantKeys)
{
}
}
Run Code Online (Sandbox Code Playgroud)
我得到的消息是System.Web.MVC.IValueProvider不包含Keys的定义.有人可以告诉我如何解决这个问题.
有人可以帮我理解这行jquery代码吗?:
$(this).find('input[type="submit"]:not(.cancel), button').click(function ()
Run Code Online (Sandbox Code Playgroud)
我特别感兴趣.cancel,因为整个jquery代码块(这里没有包含)用于验证页面,我试图阻止验证,如果用户点击取消按钮.我猜测上面的代码行说它点击的提交按钮不是取消按钮,然后继续.
但我不知道如何将按钮指定为取消.
我有以下代码,我知道这些代码无法正常运行。是的,我知道如何在jQuery中执行此操作,但是在这种情况下,我无法使用jQuery。请没有jQuery的答案。
<form>
<input type="text" name="input1" onclick="alert('hello')">
<input type="text" name="input2">
<input type="text" name="input3">
</form>
<script type="text\javascript">
window.onload = function () {
var currentOnClick;
for (var i = 0; i < document.forms[0].elements.length; i++) {
currentOnClick = document.forms[0].elements[i].onclick;
document.forms[0].elements[i].onclick = function () {
if (currentOnClick) {
currentOnClick();
}
alert("hello2");
}
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
我想做的是遍历表单的元素并添加到onclick函数中。但是由于在我的上一个迭代中currentOnClick为null,因此无法按预期运行。我想保留每个元素的onclick方法,并在我创建的新函数中播放它们。
我想要的是:
单击input1时,警报“ hello”,然后警报“ hello2”
单击Input2时,警告“ hello2”
单击Input3时,警告“ hello2”
我有这个要求:
系统将记录用户显示每页的时间长度.
虽然在富客户端应用程序中微不足道,但我不知道人们通常会如何跟踪这一点.
编辑:John Hartsock
我一直对此感到好奇,在我看来,通过使用document.onunload事件可以实现这一点,可以准确地捕捉星星并停止所有页面的停留时间.基本上只要用户停留在您的网站上,您就可以始终获得除最后一页之外的每个页面的开始和停止时间.这是场景.
问题变成是可以跟踪用户何时关闭窗口或导航离开您的网站?是否可以使用onunload事件?如果没有,那么还有什么其他可能性呢?很明显,AJAX将是一条路线,但其他一些路线是什么?
基本上我试图在这个立方结果中得到一个明显的计数.但不幸的是你不能使用Count(distinct(Field))与cube和rollup(如此处所述)
这是数据的样子.(这只是一个简单的例子,我确实希望在数据中重复)
Category1 Category2 ItemId
a b 1
a b 1
a a 1
a a 2
a c 1
a b 2
a b 3
a c 2
a a 1
a a 3
a c 4
Run Code Online (Sandbox Code Playgroud)
这是我想做的,但它不起作用.
SELECT
Category1,
Category2,
Count(Distinct(ItemId))
FROM ItemList IL
GROUP BY
Category1,
Category2
WITH CUBE
Run Code Online (Sandbox Code Playgroud)
我知道我可以像这样做一个子选择来得到我想要的结果:
SELECT
*,
(SELECT
Count(Distinct(ItemId))
FROM ItemList IL2
WHERE
(Q1.Category1 IS NULL OR Q1.Category1 IS NOT NULL AND Q1.Category1 = IL2.Category1)
AND
(Q1.Category2 IS NULL OR …Run Code Online (Sandbox Code Playgroud) 我有一个来自客户端的任务来更正页面,我发现jQuery后代选择器没有按预期运行.
这是HTML的一个excrept:
<form action="http://submit.url/subscribe.php" method="post" enctype="multipart/form-data" id="mssysform8217" class="mssysform" >
<div id="mssys-formcontainer">
<div class="formfields">
<table style="width: 100%">
<div class="formfield-item" id="formfield-item-email">
<tr>
<td class="style1"><label >E-mail címe</label></td>
<td>
<input type="text" name="email" value="">
<div class="error-container">Please fill in this field!</div>
<div style="clear: both;"></div>
</td>
</tr>
</div>
</table>
</div>
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
我尝试用FireFox调试它:
这工作:
console.debug($("#mssysform8217 :input[name='email']").val());
Run Code Online (Sandbox Code Playgroud)
test@gmail.com
这没效果:
console.debug($("#mssysform8217 #formfield-item-email :input[name='email']").val());
Run Code Online (Sandbox Code Playgroud)
未定义
但:
console.debug($("#mssysform8217 #formfield-item-email"));
Run Code Online (Sandbox Code Playgroud)
[DIV#formfield项-email.formfield项目]
问题是提交脚本是由第三方应用程序生成的,它想要使用3级后代选择器.
我希望用户能够看到Html.ActionLink()在将鼠标悬停在链接上时生成的锚标记的相应URL.这是通过设置title属性来完成的,但我遇到的问题是如何获取该值:
@Html.ActionLink(@testrun.Name, "Download", "Trx",
new { path = @testrun.TrxPath }, new { title = ??)
Run Code Online (Sandbox Code Playgroud)
如何指定ActionLink将生成的URL?我可以硬编码我猜的东西,但这违反了DRY.
我有下一个脚本:
var Game = Backbone.Model.extend({});
var GamesCollection = Backbone.Collection.extend({
model: Game
});
var games = new GamesCollection();
var portal = new Game({name: 'Tetris', year: '2017'});
games.add(portal);
console.log(games.get(0));
Run Code Online (Sandbox Code Playgroud)
为什么"games.get(0)"返回'undefined'?可能是我用get方法不正确吗?
如果用户单击"全选"按钮,我只想检查页面上的所有复选框.
在身体里:
<button id="checkall">Select All</button>
Run Code Online (Sandbox Code Playgroud)
jQuery的:
<head>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#checkall').click(function () {
$("input[type=checkbox]").each( function() {
$(this).attr('checked', true);
});
});
</script>
</head>
Run Code Online (Sandbox Code Playgroud)
而且复选框是由一点点php生成的:
echo '<li>';
echo '<input type="checkbox" name="checkbox[]" value="'.$x.'" />'.$x.'<br/>';
echo '</li>';
Run Code Online (Sandbox Code Playgroud)
谁能告诉我我做错了什么?
c# ×3
javascript ×3
jquery ×3
asp.net-mvc ×2
html ×2
.net ×1
actionlink ×1
backbone.js ×1
group-by ×1
sql ×1
sql-server ×1
t-sql ×1
web ×1