1

我有一个列表视图,带有搜索过滤器,几乎 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');
4

1 回答 1

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>​
于 2012-11-16T13:38:02.127 回答