-1
作为NativeScript的iOS/Android应用我正在建设的一部分,我需要:
1.搜索项目列表的搜索
2.选择一个结果
3.由于选择了一个,清除搜索结果NativeScript的ListView itemTap不会空项目
但它不工作。奇怪的是,当连接到SearchBar被清除时,相同的clearItems函数可以正常工作,但在ListView中的某个项目上点击时它不起作用。
下面是相关代码:
XML
<Page>
<AbsoluteLayout loaded="layoutLoaded">
<SearchBar hint="Search for your opponent" id="search" submit="performSearch" />
<ListView id="itemList" items="{{ itemList }}" visibility="{{ listVisible ? 'visible' : 'collapsed' }}">
<ListView.itemTemplate>
<WrapLayout>
<Image cssClass="itemImage" src="{{ image }}" />
<Label cssClass="itemLabel" text="{{ niceName }}" />
</WrapLayout>
</ListView.itemTemplate>
</ListView>
</AbsoluteLayout>
</Page>
的JavaScript
function clearItems(thisLayout){
thisLayout.bindingContext.itemList = [];
thisLayout.bindingContext.listVisible = false;
}
exports.layoutLoaded = function(args){
var thisLayout = args.object
thisLayout.bindingContext = {
itemList: [],
listVisible: false
};
var searchBar = view.getViewById(thisLayout, 'search');
searchBar.on(searchBarModule.SearchBar.clearEvent, function(args) {
clearItems(args.object.parent);
});
var itemListWrap = view.getViewById(thisLayout, 'itemList');
itemListWrap.on('itemTap', function(args){
var page = args.object.parent;
clearItems(page);
});
}
非常感谢的人谁可以提供帮助。我认为清单是自己的父列表的列表项更复杂一些。
我不完全理解你的问题,但两件事情。首先,将bindingContext绑定到可观察对象/数组(请参阅https://docs.nativescript.org/bindings.html和https://docs.nativescript.org/ApiReference/data/observable-array/HOW-TO.html )。秒,通过清空数组而清除列表而不是重新定义它,例如:while(itemList.length> 0){itemList.pop(); }。以下是解释如何使用可观察对象/数组的视频:https://youtu.be/MhwBpVRfljU?t = 1402 –