鍍金池/ 問答/Java  Python  C  C++  HTML/ 解析模塊的數(shù)據(jù)傳不到邏輯模塊

解析模塊的數(shù)據(jù)傳不到邏輯模塊

  1. SampleTime.prototype.getSampleStateBySampleNo 是數(shù)據(jù)解析模塊;
    SampleTime是JS交互邏輯模塊;
    SampleTime.prototype._setSampleNo是關(guān)聯(lián)模塊;
  2. 關(guān)聯(lián)模塊傳輸數(shù)據(jù)到解析模塊是正常的,但是傳輸?shù)浇换ツK就沒數(shù)據(jù)了,本來調(diào)用存儲過程是正
    常的,代碼量有些大,不便之處多多海涵,同事說this的指向有問題,但不知道怎么修改
  3. 所有代碼:

    // JScript 文件

function SampleTime() {

var times = this._rowsData;
console.log(times);
//計算寬度,總和:
var totals = 0;
for (var  total= 0;total < times.length;total++){
    totals += times[total];
}
var firstTimes = [];
for (var f=0;f < times.length;f++){
    if (times[f] != 0) {
        firstTimes.push(Math.round(100/totals*times[f]) + '%');
    }else{
        firstTimes.push('0%');
    }
}

var list = [
    ['采樣', times[0]],
    ['送檢', times[1]],
    ['簽收', times[2]],
    ['已登記', times[3]],
    ['IOM', times[4]],
    ['離心', times[5]],
    ['去蓋', times[6]],
    ['測試中', times[7]],
    ['已上傳', times[8]],
    ['已發(fā)送', times[9]]
];

var container = document.querySelector('.container');
var timeBox = document.querySelector('.timeBox');
//橫向:
var _htmlLine = '<p>耗時</p>';
//縱向
var _htmlParallel = '<p>耗時明細</p>'

for (var j = 0;j < list.length; j++) {
    //橫向:
    _htmlLine +=
        '<div class="lineBox" style="width:'+ firstTimes[j] +'" > ' +
            '<div class="top"><b>●</b><p>' ;
                    if(firstTimes[j]!=='0%') {
                        _htmlLine += list[j][1];
                    }
    _htmlLine+= '</p></div>' +
                    '<div class="bottom"><p>';
                        if(firstTimes[j]!=='0%') {
                            _htmlLine += list[j][0];
                        }
    _htmlLine+= '</p></div></div>';



    //縱向:
    _htmlParallel +=
        '<div class="time" style="height:'+ firstTimes[j] +'">' +
            '<div class="left"><b>●</b><P>';
           if(firstTimes[j]!=='0%'){
               _htmlParallel += list[j][0];
           }
    _htmlParallel += '</P></div>' +
        '<div class="right"><p>';
        if(firstTimes[j]!=='0%') {
            _htmlParallel += '時間: ' + this.Gos[0];
        }
    _htmlParallel += '</p><span>';
        if(firstTimes[j]!=='0%') {
            _htmlParallel += '描述: ' + this.Gos[1];
        }
    _htmlParallel += '</span></div></div>'

}
container.innerHTML = _htmlLine;
timeBox.innerHTML = _htmlParallel;


//TAT
var rounds = document.querySelector('div.round');
var _watchHtml = '';

this._valueDatas.forEach(function (value,index,array) {
    value = eval('('+ value +')');
    //console.log(value)
    var maxTat = value.c3text;
    var fwcTat = value.c4text;
    var difTat = (maxTat - fwcTat);
    var colors = difTat/maxTat;
    var _valueLengths = value.c3text.length;

    _watchHtml += '<div class="watchBox"><div class="watch w'+index+'"></div></div>'
    var wat=document.createElement('div');
    wat.setAttribute('class','watchBox');
    wat.innerHTML='<div class="watch w'+index+'"></div>';
   // rounds.innerHTML = _watchHtml;
    rounds.appendChild(wat)

    //儀表盤配置參數(shù)
    var watch = echarts.init(document.querySelector('.w'+index));
    var option = {
        toolbox: {
            show: false
        },
        tooltip: {
            formatter: "{a} <br/> : {c}%"
        },
        textStyle: {
            fontSize: 8,
        },
        series: [
            {
                type: 'gauge',
                radius: '100%',
                clockwise: true,
                splitNumber: _valueLengths,
                center: [110, 90],
                min: 0,
                max: Math.round(value.c3text),
                detail: {
                    formatter: '{value}min',
                    fontSize: 10,
                    offsetCenter: ['0%','60%']
                },
                data: [{value: difTat}],
                axisLine: {
                    show: true,
                    lineStyle: {
                        color: [
                            [colors,'#29b6f6'],
                            [fwcTat/maxTat,'#ffa726'],
                            [1,'#f44336'],
                        ]
                    }
                },
                splitLine: {
                    show: false
                },
                axisLabel: {
                    distance: 5,
                    fontSize: 10,
                    formatter: function(v){
                        return v.toFixed(0);
                    },
                },
                pointer: {
                    show: true,
                    length: '60%',
                    width: 5,
                }
            }
        ]
    }
    watch.setOption(option);
})

//console.log(this._datas)
//條形圖
var line = echarts.init(document.getElementById('line'));
line.showLoading();   //加載數(shù)據(jù)時動畫顯示
line.setOption({
    title: {
        text: '測試項所花時間',
        top: '10%',
        textStyle: {
            color: '#9c27b0',
            fontSize: 18
        }
    },
    tooltip: {
        //trigger: 'axis',   //放大鏡
        axisPointer: {
            type: 'shadow'
        }
    },
    grid: {
        left: '0%',
        right: '0%',
        bottom: '0%',
        containLabel: true
    },
    xAxis: {
        type: 'value',
        boundaryGap: [0, 0.5],
        minInterval: 1,

    },
    yAxis: {
        type: 'category',
        data: this._values,
        axisTick: {
            alignWithLabel: true,
        }
    },
    series: [
        {
            name: '選項之間所花時間',
            type: 'bar',
            data: this._datas,
        }
    ]
})
line.hideLoading();   //加載完畢后隱藏

}

//調(diào)用標(biāo)本信息
SampleTime.prototype._setSampleNo = function( nSampleNo ) {

//清除表數(shù)據(jù)
this._tableLogInfo = null;
//alert(nSampleNo);
SampleTime.prototype.getSampleStateBySampleNo(nSampleNo);
SampleTime();

}

// 交互模塊,柱狀圖 橫向 縱向時間軸
SampleTime.prototype.getSampleStateBySampleNo = function (p) {

//console.log(p);
//橫向存儲過程
var Request = Global.NewMessage();
Request.ProcedureName = "[proc_datalink_getsample_module]";
Request.ParameterNames = ["SampleNo"];
Request.ParameterDataTypes = ["int"];
Request.ParameterValues = [p||1]
//PostMessage 異步需回調(diào)
var Return = Global.SendMessage("DB_CallProcedure", Request);
var Returns = Return.Table0;
//console.log(Returns)

this.rowsData = [];
this._rowsData = [];
this._rowsData = Returns._rowsData[0];
var datas = [];
var times = [];
for (var data = 0; data < this._rowsData.length; data++) {
    times.push(this._rowsData[data]);
    datas.push(new Date(this._rowsData[data]).getMinutes());
}
//分鐘,柱狀圖 橫向時間軸
this._rowsData = datas;
console.log(this._rowsData)

//完整時間,縱向時間軸
this.rowsData = times;
this.rowsTime = []
for (var w = 0;w < this.rowsData.length;w++){
    if (this.rowsData[w] != null){
        this.rowsTime.push(this.rowsData[w]);
    }
}
//混合數(shù)組
this.dataValues = [
    ["采樣", this._rowsData[0]],
    ["送檢", this._rowsData[1]],
    ["簽收", this._rowsData[2]],
    ["已登記", this._rowsData[3]],
    ["IOM", this._rowsData[4]],
    ["離心", this._rowsData[5]],
    ["去蓋", this._rowsData[6]],
    ["測試中", this._rowsData[7]],
    ["已上傳", this._rowsData[8]],
    ["已發(fā)送", this._rowsData[9]]
]
this.dataValues.sort(function (a, b) {
    return a[1] - b[1];
});
this._values = [];
this._datas = [];
for (var i = 0; i < this.dataValues.length; i++) {
    this._values.push(this.dataValues[i][0]);
    this._datas.push(this.dataValues[i][1]);
}
//console.log(this._datas)

//縱向調(diào)用:
var Requests = Global.NewMessage();
Requests.ProcedureName = "[proc_datalink_getsample_moduleinfo]";
Requests.ParameterNames = ["SampleNo","SampleState"];
Requests.ParameterDataTypes = ["int","int"];
Requests.ParameterValues = [400,420];

var Go = Global.SendMessage("DB_CallProcedure", Requests);
this.Gos = Go.Table0._rowsData[0];

//TAT儀表盤數(shù)據(jù)調(diào)用
var configType = "machine";
var moduleName = "TATWarningCFG";
var configName = "data";
var value = top.UniformConfig.readValue(configType, moduleName, configName, "");
if (value == "") {
    return false;
}
this._valueDatas = JSON.parse(value).SearchCondition;

}
SampleTime.prototype.getSampleStateBySampleNo(1);

回答
編輯回答
絯孑氣

謝邀先!
不過先提醒你稍微學(xué)一下markdown的語法,把語句標(biāo)示出來,否則直接插入的語句可能會被系統(tǒng)處理而不能表達完整的意思了。請先處理這點。

2017年6月3日 23:48
編輯回答
冷溫柔
function SampleTime() {
    var times = this._rowsData;
    ...
    this._valueDatas.forEach(
    ...
}
//調(diào)用標(biāo)本信息
SampleTime.prototype._setSampleNo = function( nSampleNo ) {
    //清除表數(shù)據(jù)
    this._tableLogInfo = null;
    //alert(nSampleNo);
    SampleTime.prototype.getSampleStateBySampleNo(nSampleNo);//A
    SampleTime();//B
}

// 交互模塊,柱狀圖 橫向 縱向時間軸
//定義初始值的吧
SampleTime.prototype.getSampleStateBySampleNo = function (p) {
    ...
    this.rowsData = [];
    this._rowsData = [];
    this._rowsData =
    ...
}

SampleTime.prototype.getSampleStateBySampleNo(1);//C

1.為什么要用prototype來定義方法,直接函數(shù)不好么?
2.既然要用prototype來訪定義方法,那就好好使用JS面向?qū)ο蟮姆椒?/p>

問題出在:
C處代碼調(diào)用時的this為SampleTime函數(shù)對象的prototype屬性對象
A處代碼調(diào)用時的this為SampleTime函數(shù)對象的prototype屬性對象
B處代碼調(diào)用時的this為全局對象

那么也即是所你在C、A處設(shè)置的參數(shù),對B處的函數(shù)體代碼來說完全沒有用

看下下面代碼,你就會明白:

function TEST(){
    this._p="TEST";
    console.log("this_p1:"+this._p1);
    console.log("this_p2:"+this._p2);
}

TEST.prototype.fun1=function(){
    this._p="fun1";
}

TEST.prototype._run_=function(){
    TEST.prototype.fun1();
    TEST();
}

TEST.prototype.fun1=function(){
    this._p1="fun1";
}
TEST.prototype.fun2=function(){
    this._p2="fun2";
}

TEST.prototype.fun2();
TEST.prototype._run_();
//this_p1:undefined
//this_p2:undefined
console.log(TEST.prototype._p1);//fun1
console.log(TEST.prototype._p2);//fun2
console.log(this._p);//TEST
2017年10月13日 13:30