我创建了一个Ext.Mixin组件,并希望从另一个组件中调用它的一个函数。我该怎么做?一定很明显,但我现在看不到。
编辑:
scoreFunctionMap.forEach((key, function) -> executor.execute(() -> {
String simpleName = function.getClass().getSimpleName();
try {
logger.info("score function handler:[{}],begin", simpleName);
List<Map<String, Object>> mapList = function.handlerScore(items, itemDataMap);
if (mapList != null) {
List<Map<String, Object>> scoreList = new ArrayList<>();
mapList.forEach(val -> {
scoreList.add(val);
for (Map<String, Object> map : scoreList) {
map.put(SolrCollection.FORDEAL, SolrCollection.FORDEAL);
}
if (scoreList.size() == 1000) {
solrCrudInterface.updatePartialIndex(SolrCollection.FORDEAL, scoreList);
logger.info("handler:[{}],update index in process", simpleName);
scoreList.clear();
}
});
if (scoreList.size() > 0) {
**solrCrudInterface.updatePartialIndex(SolrCollection.FORDEAL, scoreList);**
logger.info("handler:[{}],update index in process", simpleName);
}
logger.info("score function handler:{},update index end ", simpleName);
}
} catch (Throwable e) {
logger.error("error:{}", simpleName, e);
}
}));
public void updatePartialIndex(String collection, List<Map<String, Object>> data) {
List<PartialUpdate> updates = new ArrayList<>();
if (data == null || data.size() == 0) {
logger.warn("data size is 0");
return;
}
for (Map<String, Object> datum : data) {
if (datum.containsKey("id")) {
PartialUpdate partialUpdate = new PartialUpdate("id", datum.get("id"));
datum.remove("id");
datum.forEach(partialUpdate::setValueOfField);
updates.add(partialUpdate);
}
}
if (updates.size() == 0) {
logger.warn("data size is 0");
return;
}
UpdateResponse updateResponse = solrTemplate.saveBeans(collection, updates);
solrTemplate.commit(collection);
logger.info("update collection:{},collection_size:{}, success,time:{}ms", collection, updates.size(), updateResponse.getElapsedTime());
}
如何调用 myfunction() ?
答案 0 :(得分:1)
当您将mixin包含在组件中时,mixin提供的所有功能都包含在组件本身中。 因此,当您引用已创建的组件时,就无法在组件本身上调用该函数。
Ext.define('ABC.mixin.MyMixin', {
extend: 'Ext.Mixin',
myfunction: function () {
//do stuff
}
});
Ext.define('ABC.view.MyView', {
mixins: ['ABC.mixin.MyMixin'],
// ...other config stuff
});
let myView = Ext.create('ABC.view.MyView'); // concreate Object of the class ABC.view.MyView
myView.myfunction(); // we can call the function of the mixin on the Object directly.
有关更多信息,请参见ExtJs documentation
答案 1 :(得分:0)
API Docs似乎可以提供您所需的信息。您只需在所需的组件中包含mixin,如下所示:
Ext.define('ABC.view.MyComponent', {
mixins: ['ABC.mixin.MyMixin'],
initComponent() {
this.myfunction();
this.callParent();
}
});
然后从组件的范围调用所需的mixin函数