在jQuery mobile listview中刷新单个li

时间:2012-11-16 11:57:15

标签: jquery-mobile

我有一个列表视图,带有搜索过滤器,差不多有300 <li>

刷新列表视图需要大约7秒,但有时我只想更新单个<li>的数据图标。

有没有办法在不刷新完整列表视图的情况下刷新单个<li>

编辑:

示例

<ul data-role="listview" id="myList">
    <li id="a" data-icon="check"><a href="">A</a></li>
    <li id="b" data-icon="check"><a href="">B</a></li>
</ul>

解决方案

$('#a span').removeClass ('ui-icon-check');
$('#a span').addClass ('ui-icon-refresh');

1 个答案:

答案 0 :(得分:1)

这样的事情有用吗?

JS

// US Flag
var newImageSource = "http://jquerymobile.com/demos/1.2.0/docs/lists/images/us.png"; 

// this is the item you want to change
var listItemChildNeeded = 3; 

// this is the list with the found item
var listItemChildSelected = $("#myList :nth-child("+listItemChildNeeded+")"); 

// digging into the jQM markup first level
var listItemChildSelectedFirstChild = listItemChildSelected.children(); 

// digging into the jQM markup second level
var listItemChildSelectedSecondChild = listItemChildSelectedFirstChild.children(); 

// digging into the jQM markup third level
var listItemChildSelectedThirdChild = listItemChildSelectedSecondChild.children(); 

// digging into the jQM markup fourth level
var listItemChildSelectedFourthChild = listItemChildSelectedThirdChild.children(); 

// Change Great Britains Flag to the US Flag
listItemChildSelectedFourthChild.attr('src', newImageSource);


// one liner syntax
//$("#myList :nth-child(3)").children().children().children().children().attr("src","http://jquerymobile.com/demos/1.2.0/docs/lists/images/us.png");


​

HTML

<div data-role="page" id="home" class="pages" data-theme="c">
    <ul data-role="listview" id="myList">
        <li><a href="#"><img src="http://jquerymobile.com/demos/1.2.0/docs/lists/images/gf.png" alt="France" class="ui-li-icon">France <span class="ui-li-count">4</span></a></li>
            <li><a href="#"><img src="http://jquerymobile.com/demos/1.2.0/docs/lists/images/de.png" alt="Germany" class="ui-li-icon">Germany <span class="ui-li-count">4</span></a></li>
            <li><a href="#"><img src="http://jquerymobile.com/demos/1.2.0/docs/lists/images/gb.png" alt="Great Britain" class="ui-li-icon">Great Britain <span class="ui-li-count">0</span></a></li>
            <li><a href="#"><img src="http://jquerymobile.com/demos/1.2.0/docs/lists/images/fi.png" alt="Finland" class="ui-li-icon">Finland <span class="ui-li-count">12</span></a></li>
            <li><a href="#"><img src="http://jquerymobile.com/demos/1.2.0/docs/lists/images/sj.png" alt="Norway" class="ui-li-icon">Norway <span class="ui-li-count">328</span></a></li>
            <li><a href="#"><img src="http://jquerymobile.com/demos/1.2.0/docs/lists/images/us.png" alt="United States" class="ui-li-icon">United States <span class="ui-li-count">62</span></a></li>
    </ul>
</div>​