亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

融合這2個元素

融合這2個元素

慕慕森 2022-06-09 16:33:09
我不知道如何融合我在 ternaire 嘗試過的這兩部分代碼,但它沒有用if(marge[i].cas_v)    dps_cote.push({        x: i,        label: cote[i].x,        y: cote[i].y,        color: 'green',        indexLabelFontColor : "red",        indexLabelFontWeight: "bold",        indexLabel: marge[i].cas_v.toString()    });// CAS_V = NULLelse    dps_cote.push({        x: i,        label: cote[i].x,        y: cote[i].y,        color: 'green',        indexLabelFontColor : "red",        indexLabelFontWeight: "bold",        indexLabel: ""    });
查看完整描述

3 回答

?
慕森卡

TA貢獻1806條經驗 獲得超8個贊

您可以嘗試以下方法


dps_cote.push({

        x: i,

        label: cote[i].x,

        y: cote[i].y,

        color: 'green',

        indexLabelFontColor : "red",

        indexLabelFontWeight: "bold",

        indexLabel: marge[i].cas_v?marge[i].cas_v.toString():""

    });


查看完整回答
反對 回復 2022-06-09
?
慕婉清6462132

TA貢獻1804條經驗 獲得超2個贊

let object = {

    x: i,

    label: cote[i].x,

    y: cote[i].y,

    color: 'green',

    indexLabelFontColor : "red",

    indexLabelFontWeight: "bold",

}

if (marge[i].cas_v) {

    object.indexLabel = marge[i].cas_v.toString();

    dps_cote.push(object);

} else {

    dps_cote.push(object);

}


查看完整回答
反對 回復 2022-06-09
?
慕容708150

TA貢獻1831條經驗 獲得超4個贊

所有的值都是用任意值定義的,以便提供一個有效的答案。

  1. 首先聲明和/或定義變量

  2. 然后流控制,如條件if/else if/else和/或三元let x = 0 > y ? z : a

  3. indexLabel由于具有兩個可能值之一,請避免重寫像定義兩次的對象那樣的代碼。如果您練習#1,那么重復的代碼膨脹就不會成為問題。

三元組的不同之處if/else if/else在于它就像一個表達式:

let iL = marge[i].cas_v ? marge[i].cas_v.toString() : "";

/* 

if `marge[i].cas_v` exists then `iL` is `marge[i].cas_v.toString()`

otherwise it is `""`

*/

obj.indexLabel = iL;

// whatever `iL` ends up to be -- its assigned to `obj.indexLabel` 

演示

/* 

if i = 0 then indexLabel: "11"

if i = 1 then indexLabel: "121"

if i = 2 then indexLabel: "14641"

*/

let i = 0;

let cote = [{x: 0, y: 0}, {x: 1, y: 0}, {x: 0, y: 1}];

let marge = [{cas_v: 11}, {cas_v: 121}, {cas_v: 14641}];

let dps_cote = [];

let obj = {

  x: i,

  label: cote[i].x,

  y: cote[i].y,

  color: 'green',

  indexLabelFontColor: "red",

  indexLabelFontWeight: "bold",

  indexLabel: ""

};


let iL = marge[i].cas_v ? marge[i].cas_v.toString() : "";


obj.indexLabel = iL;


dps_cote.push(obj);


console.log(dps_cote);


查看完整回答
反對 回復 2022-06-09
  • 3 回答
  • 0 關注
  • 106 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號