Задать вопрос
  • Как сделать прижатый к низу экрана div находящийся над таблицей?

    RussianNinja
    @RussianNinja
    <div class='fixed'></div>
    
    <style>
    .fixed {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
    }
    </style>
    Ответ написан
    1 комментарий
  • Как записывать в разные div взависимости от значения ключа json?

    Stalker_RED
    @Stalker_RED
    json.response.items.forEach(item => {
      switch (item.type) {
        case 1:
          $('div.list').append(item.text);
          break;
        case 2:
          $('div.list2').append(item.text);
          break;
      }
    });
    Ответ написан
    2 комментария
  • Как посчитать сумму за день?

    Babayka_od
    @Babayka_od
    Full-stack developer
    var json = JSON.parse(`{
      "response": {
        "items": [
          {
            "id": "898",
            "date": "18 января, 2021",
            "time": "22:38",
            "account": "%account%",
            "category": "%category%",
            "amount": "1000.00",
            "amount_html": "%html%",
            "type": "1",
            "type_html": "%type_html%",
            "balance": "%balance%",
            "comment": "-"
          },
          {
            "id": "898",
            "date": "19 января, 2021",
            "time": "22:38",
            "account": "%account%",
            "category": "%category%",
            "amount": "1000.00",
            "amount_html": "%html%",
            "type": "1",
            "type_html": "%type_html%",
            "balance": "%balance%",
            "comment": "-"
          },
          {
            "id": "898",
            "date": "19 января, 2021",
            "time": "22:38",
            "account": "%account%",
            "category": "%category%",
            "amount": "1000.00",
            "amount_html": "%html%",
            "type": "1",
            "type_html": "%type_html%",
            "balance": "%balance%",
            "comment": "-"
          },
          {
            "id": "898",
            "date": "19 января, 2021",
            "time": "22:38",
            "account": "%account%",
            "category": "%category%",
            "amount": "1000.00",
            "amount_html": "%html%",
            "type": "1",
            "type_html": "%type_html%",
            "balance": "%balance%",
            "comment": "-"
          },
          {
            "id": "898",
            "date": "20 января, 2021",
            "time": "22:38",
            "account": "%account%",
            "category": "%category%",
            "amount": "1000.00",
            "amount_html": "%html%",
            "type": "1",
            "type_html": "%type_html%",
            "balance": "%balance%",
            "comment": "-"
          },
          {
            "id": "898",
            "date": "21 января, 2021",
            "time": "22:38",
            "account": "%account%",
            "category": "%category%",
            "amount": "1000.00",
            "amount_html": "%html%",
            "type": "1",
            "type_html": "%type_html%",
            "balance": "%balance%",
            "comment": "-"
          },
          {
            "id": "898",
            "date": "21 января, 2021",
            "time": "22:38",
            "account": "%account%",
            "category": "%category%",
            "amount": "1000.00",
            "amount_html": "%html%",
            "type": "1",
            "type_html": "%type_html%",
            "balance": "%balance%",
            "comment": "-"
          }
        ]
      }
    }`);
    
    const accountsGroupedByDates = json.response.items
      .reduce((acc, item) => {
        if (Array.isArray(acc[item.date])) {
          acc[item.date].push(item)
        } else {
          acc[item.date] = [item];
        }
        
        return acc;
      }, {})
    const listBalances = Object.entries(accountsGroupedByDates)
      .map(([date, accountsList]) => {
        return {
          date,
          accounts: accountsList,
          dailyBalance: accountsList.reduce((acc, item) => {
            const amount = Number(item.amount);
            return item.type === '1' ? acc + amount : acc - amount;
          }, 0)
        }
      });
    
    $('div.timeline').append(listBalances.map(item => {  
        let div = `<div class="time-label"><span class="bg-primary">${item.date} - ${item.dailyBalance}</span></div>`
        item.accounts.forEach(_item => {
            div += `              <div>
                    ${_item.type_html}
                    <div class="timeline-item">
                      <span class="float-right" style="padding: 5px 10px 5px 5px;">${_item.amount_html}</span>
                      <h3 class="timeline-header">${_item.account}</h3>
                      <div class="timeline-body"><small class="float-right">${_item.time}</small><b>${_item.category}</b><br>${_item.comment}</div>
                    </div>
                  </div>`
        })
        return div;
    }).join(''));
    Ответ написан
    4 комментария
  • Как сделать редирект с http и www на https без www?

    RewriteEngine on
    RewriteCond %{HTTPS}_%{HTTP_HOST} ^(?|off_(?:www\.)?(.*)|on_www\.(.*)) [NC]
    RewriteRule .* https://%1/$0 [R=301,L]
    Ответ написан
    Комментировать