2017-01-09 38 views
0

我有這樣的小聰明選擇:Framework7智能選擇顯示所選項目

<div class="list-block"> 
    <ul> 
     <li> 
      <a href="#" class="item-link smart-select" data-back-on-select="true" data-open-in="popup"> 
       <select name="projects" id="projects"> 
        <option value="0" selected>Please choose...</option> 
        <option value="1" >House build</option> 
       </select> 
       <div class="item-content"> 
        <div class="item-inner"> 
         <div class="item-title">Aufträge</div> 
        </div> 
       </div> 
      </a> 
     </li> 
    </ul> 
</div> 

當用戶選擇一個項目,我創建了一個cookie的在裏面寫的值。重新加載或關閉頁面後,我在Cookie中選擇了該項目。這樣可行。但是,我認爲「請選擇」條目而不是選定的條目。但是,當我點擊列表上正確的項目是選擇,但然後關閉我再次看到的列表請選擇。 這是我如何選擇的值:

$$("#projects").val(getCookie("timerTasks")); 

回答

1

那麼,我跑到這之前。您可以從cookie選擇值後更新item-title類:

在細節:

// Select your value 
$$("#projects").val(getCookie("timerTasks")); 

// Selected value text 
var selected_text = $$("#projects").find("option:selected").text(); 

// Change item-title 
$$("#projects").parent().find('.item-title').html(selected_text); 

一號線:

$$("#projects").val(getCookie("timerTasks")).parent().find('.item-title').html($$("#projects").find("option:selected").text()); 

你可以看到this is a common issue那裏,我不知道爲什麼它尚未修復。

2

@tinyCoder幾乎是正確的,除了你需要更新.item-after而不是.item-title.item-title是智能選擇的「標籤」,.item-after顯示選定的值。

此外,由於.html()將呈現HTML,我們只需要文本,我認爲使用.text()更合適。所以,我的一行是這樣的:

$$("#projects").val(getCookie("timerTasks")).parent().find('.item-after').text($$("#projects").find("option:selected").text()); 

Framework7 v1.6.5(2017年九月)

+0

謝謝你的更新湯米,我太遙遠Framework7的,現在我真不不知道最近的新聞,它有兼容性問題,讓我去土生土長。 – tinyCoder