Backbone.js code to replace variables on condition

Viewed 23

There is code in backbone js, On click on Aggregate need run spl query aggregate_spl and on click on Maximum severity run maxseverity_spl query.

Code was there, I added the following changes, but the const spl variable executed at first time only. After clicking on Maximum severity the code in if-loop not running. So that value of spl is not updated.

And there are variables $selectedServiceId$ $earliest$ $latest$ $maxSeverityMacroString$ that need to replace in spl query.

SearchManager is function in https://docs.splunk.com/DocumentationStatic/WebFramework/1.0/compref_searchmanager.html

_updateSearchType: function() {
var maxSeverityMacroString = '`metrics_service_level_kpi_only`';
if (this.userSettingsModel && this.userSettingsModel.get('searchType') === 'maxseverity') {
    maxSeverityMacroString = '`metrics_service_level_max_severity_and_service_health_score`';
       console.log("In maxseverity");
}
        console.log("maxSeverityMacroString:", maxSeverityMacroString)
        this.tokens.set('maxSeverityMacroString', maxSeverityMacroString);
},

// KPI Search (manager) for the Side Panel. Used by ServiceKpisTable to fetch individual KPI results
if (!this.kpiHealthManagerBase) {
 console.log("eeeeee-----2>");
 const aggregate_spl = 'some aggregate spl query which have $selectedServiceId$ $earliest$ $latest$ $maxSeverityMacroString$ and two more variables';
 const maxseverity_spl = 'some max severity spl query which have $selectedServiceId$ $earliest$ $latest$ $maxSeverityMacroString$ and two more variables';
 const spl = this.userSettingsModel && this.userSettingsModel.get('searchType') === 'maxseverity' ?  maxseverity_spl : aggregate_spl;
console.log("eeeeee spl-----2>", spl);
this.kpiHealthManagerBase = new SearchManager({
    /* old code
    search: 'some spl query which have $selectedServiceId$ $earliest$ $latest$ and two more variables',
    */
    earliest_time: '$earliest$',
    latest_time: '$latest$',
    indexedRealtime: '$indexedRealtime$',
    indexedRealtimeOffset: 60,
    id: 'kpi-health-manager-base',
    auto_cancel: 65, // should be > 1 minute
    check_risky_command: true,
    risky_error_message: AppSrcSearchUtils.RISKY_ERROR_MESSAGE_SHORT
   }, {tokens: true});
}

I need some help because I do not know backbone js.

0 Answers
Related