【JS】邏輯處理

1.計算會員進度api

 

 

 const a = res.data.directCount(當前充值點券) / nextLevelData.map(item => item.direct_number(下一級須要點券)); //得出小數const c = ((Dimensions.get('window').width - 160) / 375 * Dimensions.get('window').width) / 2; (進度條長度) 會員進度: width1: 0.5 * 140 = 70 (假設)

2.計算小數點.toFixed(2) 取小數點後兩位ide

3.後臺傳值來選取選項Optionpost

 

 

 

const select = [
    {
        name: '篩選時間',
        type: 'date',
        dataIndex: ['start_time', 'end_time']
    },
    {
        name: '交易所',
        type: 'select',
        option: [
            { id: 'huobipro', name: 'huobipro' },
            { id: 'binance', name: 'binance' }
            
        ],
        dataIndex: 'exchange'
    },
    {
        name: '交易對',
        type: 'select',
        option: [],
        dataIndex: 'symbol'
      }
]

componentDidMount() {
        this.getSymobls()
    }

  getSymobls() {
        HttpUtils.postForm('/api/teacher/trade/exchange/symbols', {}).then(res => {
          if (res.status === 10000) {
            let arr1 = new Set(res.data.map((item) => item.symbol))
            let symbol = Array.from(arr1).map(item => ({id: item, name: item}));
            select[2].option = symbol; //添加列表
            this.setState({
              select: this.state.select,
            })
          }
        }).catch((err) => {
          console.log(err);
        })
      }

後臺傳來的數據this

  1 {
  2   "data": [
  3     {
  4       "id": 1,
  5       "created_at": "0001-01-01T00:00:00Z",
  6       "updated_at": "0001-01-01T00:00:00Z",
  7       "deleted_at": null,
  8       "exchange": "huobipro",
  9       "symbol": "ADA/USDT",
 10       "left_coin": "ADA",
 11       "right_coin": "USDT",
 12       "min_unit_amount": 1
 13     },
 14     {
 15       "id": 2,
 16       "created_at": "0001-01-01T00:00:00Z",
 17       "updated_at": "0001-01-01T00:00:00Z",
 18       "deleted_at": null,
 19       "exchange": "huobipro",
 20       "symbol": "TRX/USDT",
 21       "left_coin": "TRX",
 22       "right_coin": "USDT",
 23       "min_unit_amount": 1
 24     },
 25     {
 26       "id": 3,
 27       "created_at": "0001-01-01T00:00:00Z",
 28       "updated_at": "0001-01-01T00:00:00Z",
 29       "deleted_at": null,
 30       "exchange": "binance",
 31       "symbol": "ADA/USDT",
 32       "left_coin": "ADA",
 33       "right_coin": "USDT",
 34       "min_unit_amount": 11
 35     },
 36     {
 37       "id": 4,
 38       "created_at": "0001-01-01T00:00:00Z",
 39       "updated_at": "0001-01-01T00:00:00Z",
 40       "deleted_at": null,
 41       "exchange": "binance",
 42       "symbol": "EOS/USDT",
 43       "left_coin": "EOS",
 44       "right_coin": "USDT",
 45       "min_unit_amount": 11
 46     },
 47     {
 48       "id": 5,
 49       "created_at": "0001-01-01T00:00:00Z",
 50       "updated_at": "0001-01-01T00:00:00Z",
 51       "deleted_at": null,
 52       "exchange": "huobipro",
 53       "symbol": "EOS/USDT",
 54       "left_coin": "EOS",
 55       "right_coin": "USDT",
 56       "min_unit_amount": 1
 57     },
 58     {
 59       "id": 6,
 60       "created_at": "0001-01-01T00:00:00Z",
 61       "updated_at": "0001-01-01T00:00:00Z",
 62       "deleted_at": null,
 63       "exchange": "huobipro",
 64       "symbol": "ETH/USDT",
 65       "left_coin": "ETH",
 66       "right_coin": "USDT",
 67       "min_unit_amount": 1
 68     },
 69     {
 70       "id": 7,
 71       "created_at": "0001-01-01T00:00:00Z",
 72       "updated_at": "0001-01-01T00:00:00Z",
 73       "deleted_at": null,
 74       "exchange": "huobipro",
 75       "symbol": "BTC/USDT",
 76       "left_coin": "BTC",
 77       "right_coin": "USDT",
 78       "min_unit_amount": 1
 79     },
 80     {
 81       "id": 8,
 82       "created_at": "0001-01-01T00:00:00Z",
 83       "updated_at": "0001-01-01T00:00:00Z",
 84       "deleted_at": null,
 85       "exchange": "huobipro",
 86       "symbol": "ETC/USDT",
 87       "left_coin": "ETC",
 88       "right_coin": "USDT",
 89       "min_unit_amount": 1
 90     },
 91     {
 92       "id": 9,
 93       "created_at": "0001-01-01T00:00:00Z",
 94       "updated_at": "0001-01-01T00:00:00Z",
 95       "deleted_at": null,
 96       "exchange": "huobipro",
 97       "symbol": "BCH/USDT",
 98       "left_coin": "BCH",
 99       "right_coin": "USDT",
100       "min_unit_amount": 1
101     },
102     {
103       "id": 10,
104       "created_at": "0001-01-01T00:00:00Z",
105       "updated_at": "0001-01-01T00:00:00Z",
106       "deleted_at": null,
107       "exchange": "huobipro",
108       "symbol": "HT/USDT",
109       "left_coin": "HT",
110       "right_coin": "USDT",
111       "min_unit_amount": 1
112     },
113     {
114       "id": 11,
115       "created_at": "0001-01-01T00:00:00Z",
116       "updated_at": "0001-01-01T00:00:00Z",
117       "deleted_at": null,
118       "exchange": "huobipro",
119       "symbol": "XRP/USDT",
120       "left_coin": "XRP",
121       "right_coin": "USDT",
122       "min_unit_amount": 1
123     },
124     {
125       "id": 12,
126       "created_at": "0001-01-01T00:00:00Z",
127       "updated_at": "0001-01-01T00:00:00Z",
128       "deleted_at": null,
129       "exchange": "huobipro",
130       "symbol": "LTC/USDT",
131       "left_coin": "LTC",
132       "right_coin": "USDT",
133       "min_unit_amount": 1
134     },
135     {
136       "id": 13,
137       "created_at": "0001-01-01T00:00:00Z",
138       "updated_at": "0001-01-01T00:00:00Z",
139       "deleted_at": null,
140       "exchange": "binance",
141       "symbol": "EOS/USDT",
142       "left_coin": "EOS",
143       "right_coin": "USDT",
144       "min_unit_amount": 11
145     },
146     {
147       "id": 14,
148       "created_at": "0001-01-01T00:00:00Z",
149       "updated_at": "0001-01-01T00:00:00Z",
150       "deleted_at": null,
151       "exchange": "binance",
152       "symbol": "ETH/USDT",
153       "left_coin": "ETH",
154       "right_coin": "USDT",
155       "min_unit_amount": 11
156     },
157     {
158       "id": 15,
159       "created_at": "0001-01-01T00:00:00Z",
160       "updated_at": "0001-01-01T00:00:00Z",
161       "deleted_at": null,
162       "exchange": "binance",
163       "symbol": "BTC/USDT",
164       "left_coin": "BTC",
165       "right_coin": "USDT",
166       "min_unit_amount": 11
167     },
168     {
169       "id": 16,
170       "created_at": "0001-01-01T00:00:00Z",
171       "updated_at": "0001-01-01T00:00:00Z",
172       "deleted_at": null,
173       "exchange": "binance",
174       "symbol": "ETC/USDT",
175       "left_coin": "ETC",
176       "right_coin": "USDT",
177       "min_unit_amount": 11
178     },
179     {
180       "id": 17,
181       "created_at": "0001-01-01T00:00:00Z",
182       "updated_at": "0001-01-01T00:00:00Z",
183       "deleted_at": null,
184       "exchange": "binance",
185       "symbol": "BCHABC/USDT",
186       "left_coin": "BCHABC",
187       "right_coin": "USDT",
188       "min_unit_amount": 11
189     },
190     {
191       "id": 18,
192       "created_at": "0001-01-01T00:00:00Z",
193       "updated_at": "0001-01-01T00:00:00Z",
194       "deleted_at": null,
195       "exchange": "binance",
196       "symbol": "XRP/USDT",
197       "left_coin": "XRP",
198       "right_coin": "USDT",
199       "min_unit_amount": 11
200     },
201     {
202       "id": 19,
203       "created_at": "0001-01-01T00:00:00Z",
204       "updated_at": "0001-01-01T00:00:00Z",
205       "deleted_at": null,
206       "exchange": "binance",
207       "symbol": "LTC/USDT",
208       "left_coin": "LTC",
209       "right_coin": "USDT",
210       "min_unit_amount": 11
211     }
212   ],
213   "message": "success",
214   "status": 10000
215 }
後臺傳來的Symbol數據

 4.刷新頁面的時候 不要從 NaN 跳到數字 能夠接受從0跳,可是不能接受NaNspa

this.state = {
     balance:0
}

<Text>{this.state.balance?(this.state.balance / 10000).toFixed(2):'0.00'}</Text>
相關文章
相關標籤/搜索