2016-11-04 83 views
0

我在出場順序在UI顯示如何使一個特定的下拉菜單選擇先來

  1. 頁腳
  2. BLABLA

我希望有一個下拉和元素在UI中顯示Header頂部位置的下拉列表。

  1. 部首
  2. 頁腳
  3. BLABLA

代碼UI:

<select id="simTextEditorSelection" onchange="ShowTextEditorBasedOnSelection();" style="float:right;"> 
    @foreach (PageInfoMV anItemForEditor in Model.ItemContents) 
    { 
     <option value="@anItemForEditor.ItemId">@anItemForEditor.ItemDisplayText</option> 
    } 

我可以以某種方式在代碼提及上面顯示特定ID作爲默認(TOP位置)。

Model.ItemContents:

public List<PageInfoMV> ItemContents 
{ 
    get 
    { 
     if (this.itemContents == null) { this.itemContents = new List<PageInfoMV>(); } 

     if (!this.itemContents.Any(x => x.ItemId == Constants.HEADER_ID)) 
     { 
      this.itemContents.Add(new PageInfoMV() { ItemId = Constants.HEADER_ID, ItemDisplayText = Constants.HEADER_DISPLAY_TEXT }); 
     } 

     if (!this.itemContents.Any(x => x.ItemId == Constants.FOOTER_ID)) 
     { 
      this.itemContents.Add(new PageInfoMV() { ItemId = Constants.FOOTER_ID, ItemDisplayText = Constants.FOOTER_DISPLAY_TEXT }); 
     } 

     return this.itemContents; 
    } 

    set { this.itemContents = value; } 
} 

Constants.cs

public static readonly string HEADER_ID = "-1000"; 
public static readonly string FOOTER_ID = "-1001"; 

它只是一個代碼段。如果需要更多的代碼塊,請讓我知道。謝謝。

+0

Howz'Constants'樣子? –

+0

添加了代碼片段。 – Unbreakable

回答

0

如果你對ItemContents有控制權,我會建議增加一個任意值來排列你的內容值;例如標題是0,頁腳是1個等等,那麼你可以使用這個在你的觀點做一個OrderBy()

@foreach (PageInfoMV anItemForEditor in Model.ItemContents.OrderBy(ic => ic.OrderValue)) 
{ 
    ... 
} 

編輯:

@foreach (PageInfoMV anItemForEditor in Model.ItemContents.OrderBy(ic => ic.OrderValue) 
.ThenBy(ic => ic.SomeOtherValueMaybeName)) 
{ 
    ... 
} 
:對剩餘項目

可選的附加訂購

+0

我猜測它會影響顯示過程中所有下拉內容的順序? – Unbreakable

+0

它可以,但如果你給其餘的相同的價值,但高於頁腳和標題,你可以然後命名的名稱或任何你想要的。例如,其他的一切都是10. – JanR

+0

我會盡力回覆你。非常感謝。 – Unbreakable

0

如果您的標題選項值是常量,那麼您應該將其設置在標題頂部。

<select id="simTextEditorSelection"> 
    <option value="Footer">Footer</option> 
    <option value="Header"> Header</option> 
    <option value="Blabla">Blabla</option> 
</select> 
<script> 
     var val1=$("#simTextEditorSelection").find('option:eq(0)').val(); 
     $('#simTextEditorSelection option[value="Header"]').insertBefore('#simTextEditorSelectionoption[value="'+val1+'"]'); 
</script> 

var val1=$("#simTextEditorSelection").find('option:eq(0)').val(); 
 
$('#simTextEditorSelection option[value="Header"]').insertBefore('#simTextEditorSelection option[value="'+val1+'"]');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<select id="simTextEditorSelection"> 
 
    <option value="Footer">Footer</option> 
 
    <option value="Header"> Header</option> 
 
    <option value="Blabla">Blabla</option> 
 
</select>

相關問題