How to modify the content of html? (service portal)

SNnewbie2
Tera Expert

I am creating a widget that contains different sections of information. I'm almost done but I am facing an issue. I am not able to modify the prices in both sections:

de.PNG

I can only get it to modify in one place in the website, but whenever I go to console it seems to be changing :

de.PNG

It seems like whenever I set t.data.u_pricing = strVal; it only does it once.

I have provided the script for better understanding. The problem is the last part (the two if statements) for some reason it only does one(it only shows one in the web portal).

I hope you guys can help me out since I can't figure this out.

function ($scope, spUtil, $sce, $rootScope) {

$rootScope.$broadcast('sp.update.breadcrumbs', $scope.data.breadcrumbs);

spUtil.setSearchPage('kb');

//console.log("Text" , $scope.data.text);

$scope.data.text = $sce.trustAsHtml($scope.data.text);

var c = this; //reference the client script

var arrayCP = c.data.codes_prices_array;

//console.log("Ues" + JSON.stringify(c.data.codes_prices_array));

var t = this;

var regex = /\[\[code=.*?\]\]/gi;

var match = t;

var u_pricing_content =   t.data.u_pricing;

match = t.data.u_pricing.match(regex);

//console.log("U pricing Content" + u_pricing_content);

var input;

var final_code = [];

console.log("Claudia" + match);

//if there is something to replace with

if(match != null){

//itereate through the matches eg. [[code=251]] [[code=252]]

//var i=0, len = match.length; i < len; i++//

for( var i in match){

var init_index =   match[i].indexOf("=")+1;

      var end_index = (match[i].length)-2;

// console.log("Index of =: " + init_index);//this is after =

// console.log("Index of ]: " + end_index);

final_code.push(match[i].slice(init_index, end_index));

}

// console.log("FINAL CODE : " , final_code);

}

for ( var key in t.data.codes_prices_array){

var strVal = u_pricing_content.toString();

var strVal1 = u_pricing_content.toString();

if ( final_code[0] ==   c.data.codes_prices_array[key].u_charge_code){

strVal = strVal.replace(match[0], "$" + c.data.codes_prices_array[key].u_one_time_charge);

t.data.u_pricing = strVal;

  console.log("FINAL VAL" , strVal);

}

  if( final_code[1] ==   c.data.codes_prices_array[key].u_charge_code){

strVal1 = strVal1.replace(match[1], "$" + c.data.codes_prices_array[key].u_price);

  t.data.u_pricing = strVal1;

//almost done I just need to figure how to display the monthly price in the website, it does display it in the console but not

//the website

console.log("FINAL VAL" , strVal1);

}

}

}

3 REPLIES 3

Gurpreet07
Mega Sage

I think the value assignation is getting overridden with each iteration of for loop so what you are getting in the html template is the value updated by last iteration of the loop. You may need to push values into an array instead and may also need to update the HTML template accordingly.


Could you provide an example of a potential solution?


What values do I need to push into an array? Could you provide an example? I tried something but It didn't work.