廣泛的不成功的搜索後,我希望你們能幫助我在這裏...如何使用dropdownlist中的對象屬性來選擇工具提示?
我所知道的:有可能通過
<script type="text/javascript">
$(function() {
$("#someDropDownForList option").each(function() {
$(this).attr({ 'title': $(this).html() });
});
});
</script>
產生的下拉列表選項提示。然而,在我的情況我要爲用戶提供更多的信息,用戶在
<html>
<body>
<div>
@Html.DropDownListFor(
m => m.SomeModelProperty,
new selectList(Model.ListWithObjects, "Property1", "Property1"),
new { @id="someDropDownForList"})
</div>
</body>
</html>
我如何使用jQuery使用Property2和Property3構建每個選項的工具提示文本的選項?
Property1 + " has: " + Property2 + " and " Property3
隨着親切的問候,
保羅
編輯:沒有的jQuery
<div>
<select id="someDropDownForList ">
@foreach(var item in Model.ListWithObjects)
{
<option title="Some property is the @item.Property2: with the @item.Property3">
@item.Property1
</option>
}
</select>
</div>
但是「property2」和「property3」是什麼? '新SelectList()'中的第二個參數是'
我很抱歉沒有提供這些信息。 Model.ListWithObjects由具有三個(字符串)屬性的對象組成:Property1,2和3.因此,下拉列表顯示屬性1的字符串值,我想在工具提示中使用剩餘的兩個屬性。 – Paul 2011-12-21 13:40:42
使用var應該工作...我可以做一些像'var Property2 ='@ Model.ListWithObjects [0] .Property2'',我無法用排序索引替換0(如:var index = $(this).index();')雖然...任何想法? – Paul 2011-12-21 15:15:40