ich ReactJS etwas neues amReagieren rerender dynamische Komponenten (Solr)
Ich habe eine reagieren Klasse, die eine Anzahl von Elementen rendert: (Probe)
var app = app || {};
app.Results = React.createClass({
componentDidMount: function() {
},
handleUpdateEvent: function(id){
var _self = this;
var handler = function()
{
var query = _self.props.results.query;
_self.props.onSearch(query); // re-does the search to re-render items ...
// obviously this is wrong since I have to click the button twice to see the results
//
}
var optionsURL = {dataType: 'json'};
optionsURL.type= 'POST';
optionsURL.url = 'http://localhost:8983/solr/jcg/dataimport?command=delta-import&clean=false&commit=true&json.nl=map&wt=json&json.wrf=?&id='+id;
// updates index for specific item.
jQuery.ajax(optionsURL).done(handler);
},
render: function() {
var tdLabelStyle = {
width: '150px'
}
return (
<div id="results-list">
{this.props.results.documents.map(function (item) {
return (
<div id={item.id} key={item.id} className="container-fluid result-item">
<div className="row">
<div className="col-md-6">
<table>
<tr><td colspan="2">{item.name}</td></tr>
<tr style={{marginTop:'5px'}}><td style={tdLabelStyle}><b>Amount:</b></td><td>{item.amount}
<button type="Submit" onClick={() => {this.handleUpdateEvent(item.id)}} title="Refresh Amount" >Refresh</button>
</td></tr>
</table>
</div>
</div>
</div>
)
},this)}
</div>
);
}
});
ich einen Knopf in der Tabelle haben Dies ruft SOLR auf, um einen Delta-Import durchzuführen, und ruft dann die Auswahlfunktion erneut auf, um die neuen Daten zu erfassen. Ich mache offensichtlich die HandleUpdateEvent Funktion falsch, aber ich bin nicht 100% sicher, wie man entweder die gesamte Sache zum Rendern bekommen, oder nur das einzelne Objekt zum Rendern.
(Hoffentlich habe ich einen Sinn ...)
Jede Hilfe ist willkommen.
(onSearch Funktion)
handleSearchEvent: function (query) {
if (this.state.query != null)
{
if (this.state.query.filters != null)
{
query.filters = this.state.query.filters;
}
}
$("#load-spinner-page").show();
if (app.cache.firstLoad) {
$("body").css("background","#F8F8F8");
app.cache.firstLoad = false;
}
var _self = this;
app.cache.query = query;
docSolrSvc.querySolr(query, function(solrResults) {
_self.setState({query: query, results: solrResults});
$("#load-spinner-page").hide();
});
},
Können Sie bitte den Code an die 'onSearch' Funktion in' handleUpdateEvent' genannt hinzufügen? –
@MarkRabey Ich habe den Code im ursprünglichen Beitrag hinzugefügt. – Xyphius