Extjs 5。
我的应用程序有一个带有标记字段的表单,其中包含超过200个项目的列表。
这些项目中约有30个包含“'另一个' (例如)。 每次我选择其中一个项目时,都应该动态地添加到textareafield表单中。
我尝试了几种解决方案但没有成功,包括使用match(),indexOf()和search()javascript方法。
onSelect : function (combo, records, eOpts) {
var records = combo.getValue();
for (var i = 0, count = records.length; i < count; i++) {
while( records[i] == '%another thing%'){ //I know this is not the right way; Just to show what I'm looking for
console.log('OK'); //logic...
return;
}
}
},
我很感激建议。
提前致谢。
答案 0 :(得分:1)
试试这段代码:
onSelect: function (field, records, opts) {
// records parameter already contains all selected tags
var found = Ext.Array.filter(records, function(r) {
// conditions go here
return r.get('text') === 'aardvark' ||
r.get('text') === 'aardwolf';
});
// check if we found anything
if (found.length > 0) {
console.log(found);
}
}
小提琴:http://jsfiddle.net/wsm6an0n/2/
如果您想使用搜索等通配符,请使用indexOf
代替比较:
onSelect: function (field, records, opts) {
// records parameter already contains all selected tags
var found = Ext.Array.filter(records, function(r) {
// conditions go here
return r.get('text').indexOf('aa') !== -1; // LIKE '%aa%'
});
// check if we found anything
if (found.length > 0) {
console.log(found);
}
}