mvc2、查询和qtip问题
我遇到一个问题,在我的控制器中,我在集合中设置值并将它们存储在 ViewData 中。例如:
ViewData["ex1"] = new SelectList(ex1); // a simple collection
ViewData["ex2"] = new SelectList(group.Members, "Id", "Gender");
我将这些传递给我的视图并像这样循环。例如:
<div id="divListBox" style="overflow:auto; border:1px solid #CCCCCC; padding-left:5px; background-color:white; height: 130px">
<%
var list = this.ViewData["e2x"] as SelectList;
var pList = this.ViewData["ex1"] as SelectList;
foreach (var p in list)
{
foreach (var pil in pList)
{
if(pil.Text.Contains(p.Value)) // ex1 does contains ex2
{
%>
<input id="cbPerson" type="checkbox" value="<%= p.Value %>" />
<label for="cbPerson"><%= p.Text %></label>
<input id="cbPersonInfo" type="hidden" value="<%= pil.Text %>" /><br />
<%
}
}
}
%>
</div> ...
这是我的 jQuery。例如:
$('#divListBox > input').each(function() {
var personInfo = $('#cbPersonInfo').val();
$(this).append($('personInfo'));
$('*').qtip('hide');
$('#divListBox label').each(function() {
$(this).qtip({
content: personInfo,
show: 'mouseover',
hide: 'mouseout',
style: {
classes: 'ui-tooltip-custom',
tip: true
},
position: {
my: 'left bottom',
at: 'top right'
}
});
});
});
如果我将输入类型“隐藏”设置为“文本”,我会看到每一项的正确信息。然而,当我将鼠标悬停在它们上方时,第一个信息显示为所有这些信息的工具提示。我认为这可能是我的jquery,但我不太确定。我已经处理这个问题几个小时了,但仍然一无所获。有人可以帮忙吗?
I'm having an issue where in my controller, I'm setting values in a collection and storing them in ViewData. eg:
ViewData["ex1"] = new SelectList(ex1); // a simple collection
ViewData["ex2"] = new SelectList(group.Members, "Id", "Gender");
I'm passing these to my View and looping through like this. eg:
<div id="divListBox" style="overflow:auto; border:1px solid #CCCCCC; padding-left:5px; background-color:white; height: 130px">
<%
var list = this.ViewData["e2x"] as SelectList;
var pList = this.ViewData["ex1"] as SelectList;
foreach (var p in list)
{
foreach (var pil in pList)
{
if(pil.Text.Contains(p.Value)) // ex1 does contains ex2
{
%>
<input id="cbPerson" type="checkbox" value="<%= p.Value %>" />
<label for="cbPerson"><%= p.Text %></label>
<input id="cbPersonInfo" type="hidden" value="<%= pil.Text %>" /><br />
<%
}
}
}
%>
</div> ...
and here is my jQuery. eg:
$('#divListBox > input').each(function() {
var personInfo = $('#cbPersonInfo').val();
$(this).append($('personInfo'));
$('*').qtip('hide');
$('#divListBox label').each(function() {
$(this).qtip({
content: personInfo,
show: 'mouseover',
hide: 'mouseout',
style: {
classes: 'ui-tooltip-custom',
tip: true
},
position: {
my: 'left bottom',
at: 'top right'
}
});
});
});
if I set my input type of "hidden" to "text", I see the correct information for each one. Hoever, when i hover over them, the first information shows as tooltip for all of them. I think it may be my jquery but I'm not too sure. I've been dealing with this issue for hours now and still nothing. Can anyone please help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
foreach:
意味着您有多次相同的ID(ID始终是唯一的),因此当您对ID进行jquery选择时,Jquery会选择它找到的第一个ID,
如果您将人包装在容器中,那就更容易了。
我为您做了一个快速调整,我对此进行了测试和工作。
这段代码的意思是:对于每个带有 person 类的 div,找到带有 cbPeronInfo 类的 div 并使用它的值作为 qtip。 (当然,将 qtip 挂接到该类)
@Edit
实际上,出于语义原因,最好使用 UL 而不是(更多逻辑),但我假设您可以自己弄清楚如何更改它?如果你想以其他方式给我一个信号:)
foreach:
means you have several times the same ID (ID is ALWAYS ! unique), so when you do a jquery selec on ID, Jquery selects the first one it finds
if you wrap your person in a container it is even easier.
I made a quick adjustment for you which I tested and worked
This code means: for each div with class person, find the div inside with class cbPeronInfo and use it's value for the qtip. (and offcourse hook the qtip to that class)
@Edit
actually, for semantic reasons it is better to use a UL instead of a (more logic) but I assume you can figure out how to change that yourself? if you wanted to otherwise give me a sign :)
对于一个外部 C# 循环 'foreach (var pil in pList){' 可能会多次重新创建相同的 '" />
' 元素。
javascript
var personInfo = $('#cbPersonInfo'). val();
选择(并重复重新选择相同的元素,因此所有悬停的工具提示相同,在本例中为pil.Text
确保页面中的所有 html 元素都具有唯一的 ID。
编辑:解决方案的快速链接(http://craigsworks.com/projects/qtip_new/forum/take-tooltip-content-from-the-element-attributes-t-8.html) 。今天晚些时候将更新可能的解决方案。
For one your outer c# loop 'foreach (var pil in pList){' will recreate the same '" />
' element possibly several times.
The javascript
var personInfo = $('#cbPersonInfo').val();
selects (and re-selects the same element repeatedly, thus the same tooltip for all the hovers, in this casepil.Text
Ensure that that all html elements in your page have unique IDs.
Edit: Quick link for solution (http://craigsworks.com/projects/qtip_new/forum/take-tooltip-content-from-the-element-attributes-t-8.html) . Will update possible solution later today.