为什么构造函数没有正确设置 <h6> 文本?

我正在使用 OOP 原则来创建一堆图表。除了文本值的设置之外,一切正常。我需要设置每个图表的标题,但我得到的是空白值。


我的代码:控制器文件,即main.js通过调用构造函数(存储在 中mainSlopeGraph.js)以及包含idof<h6>元素和填充文本的参数来执行所有数据操作并创建新图形。


相关代码:


<div class="col-sm-4 descGraph">

        <h6 id="provinceNameBaloch"></h6>

        <h6 id="provinceNameICT"></h6>

        <h6 id="provinceNamePunjab"></h6>

        <h6 id="provinceNameSindh"></h6>

        <h6 id="provinceNameKPK"></h6>

        <p>Add some words talking about the trend.</p>

      </div>

main.js:


slopeGraphKPK = new SlopeGraph(

    "#chart1",

    updatedKPKData,

    dataKPKDomain,

    "#provNameKPK",

    provNameKPK

  );

  slopeGraphPunjab = new SlopeGraph(

    "#chart2",

    updatedPunjabData,

    dataPunjabDomain,

    "#provNamePunjab",

    provNamePunjab

  );

  slopeGraphICT = new SlopeGraph(

    "#chart3",

    updatedICTData,

    dataICTDomain,

    "#provNameICT",

    provNameICT

  );

  slopeGraphSindh = new SlopeGraph(

    "#chart4",

    updatedSindhData,

    dataSindhDomain,

    "#provNameSindh",

    provNameSindh

  );

  slopeGraphBaloch = new SlopeGraph(

    "#chart5",

    updatedBalochData,

    dataBalochDomain,

    "#provNameBaloch",

    provNameBaloch

  );

mainSlopeGraph.js:


  SlopeGraph = function(

  _parentElement,

  _someData,

  _someDomain,

  _provNamePlaceholder,

  _provName

) {

  this.parentElement = _parentElement;

  this.provData = _someData;

  this.scaleDomain = _someDomain;

  this.provNamePlaceholder = _provNamePlaceholder;

  this.provName = _provName;

  this.initVis();

};


SlopeGraph.prototype.initVis = function() {

  let vis = this;


  console.log(vis.provNamePlaceholder);

  console.log(vis.provName);



  $(vis.provNamePlaceholder).text(vis.provName);

  // $("#provinceName").textContent = vis.provName;

  // $("#provinceName").innerText = vis.provName;

  // $("#provinceName").innerHTML = vis.provName;

.

.

.

}

以防万一,这里是所有代码:https://github.com/SabahatPK/Data4Pakistan_SlopeGraphs 这是输出: https: //data-driven-pakistan-data-stories.netlify.com/


三国纷争
浏览 59回答 1
1回答

MMTTMM

在你的 HTML 中,你使用provinceNameKPK类似的方法,在你的 js 中,你使用provNameKPK. 所以slopeGraphKPK = new SlopeGraph(&nbsp; &nbsp; "#chart1",&nbsp; &nbsp; updatedKPKData,&nbsp; &nbsp; dataKPKDomain,&nbsp; &nbsp; "#provNameKPK",&nbsp; &nbsp; provNameKPK&nbsp; );必须是slopeGraphKPK = new SlopeGraph(&nbsp; &nbsp; "#chart1",&nbsp; &nbsp; updatedKPKData,&nbsp; &nbsp; dataKPKDomain,&nbsp; &nbsp; "#provinceNameKPK", // prov => province&nbsp; &nbsp; provNameKPK&nbsp; );
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Html5