问:
Symfony 2.8 -> 3.4 Upgrade IsGranted('IS_AUTHENTICATED_ANONYMOUSLY') Throws Errors
I'm in the process of upgrading Symfony from 2.8 to 3.4 and I have a Authentication Listener.

The constructor of the listener

```<code>  public function __construct(EntityManager $entityManager, SessionInterface $session, Security $security, LoggerInterface $logger, Redis $redis, $secret)
    {
        $this->entityManager    = $entityManager;
        $this->session          = $session;
        $this->security         = $security;
        $this->logger           = $logger;
        $this->redis            = $redis;
        $this->secret           = $secret;
    }
</code>```

On Request Function which is calling in listener

```<code>       public function onRequest(GetResponseEvent $event)
        {

        //Validate token

        //Get Authorization Header
        $headers = $event->getRequest()->headers;
        $authHeader = $headers->get('Authorization');

        //Check if Header value starts with 'Bearer'
        if($this->startsWith($authHeader, self::$BEARER_HEADER)) {

                // Allow request to be processed by controllers
               //token handler

        } else {

            $securityContext = $this->security;
            if ($securityContext->isGranted('IS_AUTHENTICATED_ANONYMOUSLY')) {
                return;
            } else {
                throw new SessionTimeoutException();
            }

        }
    }
</code>```

Service.yml

```<code>app.token_listener:
    class: Insead\MIMBundle\Listener\AuthTokenListener
    arguments: ["@doctrine.orm.entity_manager", "@session", "@security.helper", "@logger", "@redis.authtoken", "%secret%"]
    tags:
        - { name: kernel.event_listener, event: kernel.request, method: onRequest, priority: 0 }
</code>```

ACL list entry  - security.php

```<code>  'access_control' => array(
       array('path' => '^/api/(.*?)/login', 'role'=>'IS_AUTHENTICATED_ANONYMOUSLY'),
    )
</code>```

im trying to access login route with username and password but i get following error

```<code>GENERAL EXCEPTION: The token storage contains no authentication token. One possible reason may be that there is no firewall configured for this URL. in

/var/www/vendor/symfony/symfony/src/Symfony/Component/Security/Core/Authorization/AuthorizationChecker.php line 55
Exception caught by Listener::
[
  {
    "file": "/var/www/vendor/symfony/symfony/src/Symfony/Component/Security/Core/Security.php",
    "line": 65,
    "function": "isGranted",
    "class": "Symfony\\Component\\Security\\Core\\Authorization\\AuthorizationChecker",
    "type": "->",
    "args": [
      "IS_AUTHENTICATED_ANONYMOUSLY",
      null
    ]
  },
  {
    "file": "/var/www/src/Insead/MIMBundle/Listener/AuthTokenListener.php",
    "line": 135,
    "function": "isGranted",
    "class": "Symfony\\Component\\Security\\Core\\Security",
    "type": "->",
    "args": [
      "IS_AUTHENTICATED_ANONYMOUSLY"
    ]
  },
  {
    "file": "/var/www/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php",
    "line": 212,
    "function": "onRequest",
    "class": "Insead\\MIMBundle\\Listener\\AuthTokenListener",
    "type": "->",
    "args": [
      null,
      "kernel.request",
      null
    ]
  },
  {
    "file": "/var/www/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php",
    "line": 44,
    "function": "doDispatch",
    "class": "Symfony\\Component\\EventDispatcher\\EventDispatcher",
    "type": "->",
    "args": [
      [
        [
          null,
          "onKernelRequest"
        ],
        [
          null,
          "onKernelRequest"
        ],
        [
          null,
          "onRequest"
        ],
        [
          null,
          "onController"
        ],
        [
          null,
          "onKernelRequest"
        ],
        [
          null,
          "onKernelRequest"
        ],
        [
          null,
          "configure"
        ],
        [
          null,
          "onKernelRequest"
        ],
        [
          null,
          "onKernelRequest"
        ],
        [
          null,
          "onKernelRequest"
        ],
        [
          null,
          "onKernelRequest"
        ],
        [
          null,
          "onKernelRequest"
        ],
        [
          null,
          "onKernelRequest"
        ],
        [
          null,
          "onKernelRequest"
        ],
        [
          null,
          "onKernelRequest"
        ],
        [
          null,
          "onKernelRequest"
        ],
        [
          null,
          "onKernelRequest"
        ],
        [
          null,
          "onRequest"
        ]
      ],
      "kernel.request",
      null
    ]
  },
  {
    "file": "/var/www/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php",
    "line": 127,
    "function": "dispatch",
    "class": "Symfony\\Component\\EventDispatcher\\EventDispatcher",
    "type": "->",
    "args": [
      "kernel.request",
      null
    ]
  },
  {
    "file": "/var/www/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php",
    "line": 68,
    "function": "handleRaw",
    "class": "Symfony\\Component\\HttpKernel\\HttpKernel",
    "type": "->",
    "args": [
      {
        "attributes": null,
        "request": null,
        "query": null,
        "server": null,
        "files": null,
        "cookies": null,
        "headers": null
      },
      1
    ]
  },
  {
    "file": "/var/www/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php",
    "line": 200,
    "function": "handle",
    "class": "Symfony\\Component\\HttpKernel\\HttpKernel",
    "type": "->",
    "args": [
      {
        "attributes": null,
        "request": null,
        "query": null,
        "server": null,
        "files": null,
        "cookies": null,
        "headers": null
      },
      1,
      true
    ]
  },
  {
    "file": "/var/www/web/app.php",
    "line": 29,
    "function": "handle",
    "class": "Symfony\\Component\\HttpKernel\\Kernel",
    "type": "->",
    "args": [
      {
        "attributes": null,
        "request": null,
        "query": null,
        "server": null,
        "files": null,
        "cookies": null,
        "headers": null
      }
    ]
  }
]
</code>```

I have spend days on this and i still couldn't figure it out to fix it.

Im sorry if this is already answered question i tried to search and i tried things which were mentioned in various posts and it didn't resolve it. im new to symfony too.

Full Security.php

https://www.codepile.net/pile/7O1LJkpv

AuthTokenListner.php

https://www.codepile.net/pile/Xv1ZMlAP

答:
Inject AuthorizationChecker to your class

```<code>protected $authChecker;

public function __construct(AuthorizationChecker $authChecker)
    {
        $this->authChecker = $authChecker;
    }
</code>```

By injecting it in your service.yml

```<code>XXXXXXXXX:
    class: App\XXX\XXXX\XXXXX
    arguments: [ "@security.authorization_checker" ]
</code>```

And then use it to check role using isGranted

```<code>if ($this->authChecker->isGranted('IS_AUTHENTICATED_ANONYMOUSLY')) {

}
</code>```

Body:
I'm in the process of upgrading Symfony from 2.8 to 3.4 and I have a Authentication Listener.

The constructor of the listener

  public function __construct(EntityManager $entityManager, SessionInterface $session, Security $security, LoggerInterface $logger, Redis $redis, $secret)
    {
        $this->entityManager    = $entityManager;
        $this->session          = $session;
        $this->security         = $security;
        $this->logger           = $logger;
        $this->redis            = $redis;
        $this->secret           = $secret;
    }

On Request Function which is calling in listener

       public function onRequest(GetResponseEvent $event)
        {

        //Validate token

        //Get Authorization Header
        $headers = $event->getRequest()->headers;
        $authHeader = $headers->get('Authorization');

        //Check if Header value starts with 'Bearer'
        if($this->startsWith($authHeader, self::$BEARER_HEADER)) {

                // Allow request to be processed by controllers
               //token handler

        } else {

            $securityContext = $this->security;
            if ($securityContext->isGranted('IS_AUTHENTICATED_ANONYMOUSLY')) {
                return;
            } else {
                throw new SessionTimeoutException();
            }

        }
    }

Service.yml

app.token_listener:
    class: Insead\MIMBundle\Listener\AuthTokenListener
    arguments: ["@doctrine.orm.entity_manager", "@session", "@security.helper", "@logger", "@redis.authtoken", "%secret%"]
    tags:
        - { name: kernel.event_listener, event: kernel.request, method: onRequest, priority: 0 }

ACL list entry  - security.php

  'access_control' => array(
       array('path' => '^/api/(.*?)/login', 'role'=>'IS_AUTHENTICATED_ANONYMOUSLY'),
    )

im trying to access login route with username and password but i get following error

GENERAL EXCEPTION: The token storage contains no authentication token. One possible reason may be that there is no firewall configured for this URL. in

/var/www/vendor/symfony/symfony/src/Symfony/Component/Security/Core/Authorization/AuthorizationChecker.php line 55
Exception caught by Listener::
[
  {
    "file": "/var/www/vendor/symfony/symfony/src/Symfony/Component/Security/Core/Security.php",
    "line": 65,
    "function": "isGranted",
    "class": "Symfony\\Component\\Security\\Core\\Authorization\\AuthorizationChecker",
    "type": "->",
    "args": [
      "IS_AUTHENTICATED_ANONYMOUSLY",
      null
    ]
  },
  {
    "file": "/var/www/src/Insead/MIMBundle/Listener/AuthTokenListener.php",
    "line": 135,
    "function": "isGranted",
    "class": "Symfony\\Component\\Security\\Core\\Security",
    "type": "->",
    "args": [
      "IS_AUTHENTICATED_ANONYMOUSLY"
    ]
  },
  {
    "file": "/var/www/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php",
    "line": 212,
    "function": "onRequest",
    "class": "Insead\\MIMBundle\\Listener\\AuthTokenListener",
    "type": "->",
    "args": [
      null,
      "kernel.request",
      null
    ]
  },
  {
    "file": "/var/www/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php",
    "line": 44,
    "function": "doDispatch",
    "class": "Symfony\\Component\\EventDispatcher\\EventDispatcher",
    "type": "->",
    "args": [
      [
        [
          null,
          "onKernelRequest"
        ],
        [
          null,
          "onKernelRequest"
        ],
        [
          null,
          "onRequest"
        ],
        [
          null,
          "onController"
        ],
        [
          null,
          "onKernelRequest"
        ],
        [
          null,
          "onKernelRequest"
        ],
        [
          null,
          "configure"
        ],
        [
          null,
          "onKernelRequest"
        ],
        [
          null,
          "onKernelRequest"
        ],
        [
          null,
          "onKernelRequest"
        ],
        [
          null,
          "onKernelRequest"
        ],
        [
          null,
          "onKernelRequest"
        ],
        [
          null,
          "onKernelRequest"
        ],
        [
          null,
          "onKernelRequest"
        ],
        [
          null,
          "onKernelRequest"
        ],
        [
          null,
          "onKernelRequest"
        ],
        [
          null,
          "onKernelRequest"
        ],
        [
          null,
          "onRequest"
        ]
      ],
      "kernel.request",
      null
    ]
  },
  {
    "file": "/var/www/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php",
    "line": 127,
    "function": "dispatch",
    "class": "Symfony\\Component\\EventDispatcher\\EventDispatcher",
    "type": "->",
    "args": [
      "kernel.request",
      null
    ]
  },
  {
    "file": "/var/www/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php",
    "line": 68,
    "function": "handleRaw",
    "class": "Symfony\\Component\\HttpKernel\\HttpKernel",
    "type": "->",
    "args": [
      {
        "attributes": null,
        "request": null,
        "query": null,
        "server": null,
        "files": null,
        "cookies": null,
        "headers": null
      },
      1
    ]
  },
  {
    "file": "/var/www/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php",
    "line": 200,
    "function": "handle",
    "class": "Symfony\\Component\\HttpKernel\\HttpKernel",
    "type": "->",
    "args": [
      {
        "attributes": null,
        "request": null,
        "query": null,
        "server": null,
        "files": null,
        "cookies": null,
        "headers": null
      },
      1,
      true
    ]
  },
  {
    "file": "/var/www/web/app.php",
    "line": 29,
    "function": "handle",
    "class": "Symfony\\Component\\HttpKernel\\Kernel",
    "type": "->",
    "args": [
      {
        "attributes": null,
        "request": null,
        "query": null,
        "server": null,
        "files": null,
        "cookies": null,
        "headers": null
      }
    ]
  }
]

I have spend days on this and i still couldn't figure it out to fix it.

Im sorry if this is already answered question i tried to search and i tried things which were mentioned in various posts and it didn't resolve it. im new to symfony too.

Full Security.php

https://www.codepile.net/pile/7O1LJkpv

AuthTokenListner.php

https://www.codepile.net/pile/Xv1ZMlAP

Body:
Inject AuthorizationChecker to your class

protected $authChecker;

public function __construct(AuthorizationChecker $authChecker)
    {
        $this->authChecker = $authChecker;
    }

By injecting it in your service.yml

XXXXXXXXX:
    class: App\XXX\XXXX\XXXXX
    arguments: [ "@security.authorization_checker" ]

And then use it to check role using isGranted

if ($this->authChecker->isGranted('IS_AUTHENTICATED_ANONYMOUSLY')) {

}


来源: stackexchange

问:
Parameterized Scheduler in scripted pipeline
I switched from declerativ pipeline to scripted pipeline. Everything works fine only  the Parameterized Scheduler Plugin makes problems. If i have one Trigger it works and the pipeline is scheduled. If i add another trigger only the second one works. May be it's a syntax problem but everything i tried doesn't work. Any ideas?</p>

```<code>properties([
    parameters([
        booleanParam (defaultValue: true, description: 'test', name: 'test')
    ]),
    pipelineTriggers([
        parameterizedCron('15 20 * * * test=true'),
        parameterizedCron('05 20 * * * test=false')
    ])
])//properties
</code>```

答:
according to official documentation your syntax is wrong, you are missing %. Also you can use one multiline parameterizedCron.

```<code>pipeline {
    agent any
    parameters {
      string(name: 'PLANET', defaultValue: 'Earth', description: 'Which planet are we on?')
      string(name: 'GREETING', defaultValue: 'Hello', description: 'How shall we greet?')
    }
    triggers {
        cron('* * * * *')
        parameterizedCron('''
# leave spaces where you want them around the parameters. They'll be trimmed.
# we let the build run with the default name
*/2 * * * * %GREETING=Hola;PLANET=Pluto
*/3 * * * * %PLANET=Mars
        ''')
    }
    stages {
        stage('Example') {
            steps {
                echo "${GREETING} ${PLANET}"
                script { currentBuild.description = "${GREETING} ${PLANET}" }
            }
        }
    }
}
</code>```

So in your case it should be

```<code>properties([
    parameters([
        booleanParam (defaultValue: true, description: 'test', name: 'test')
    ]),
    pipelineTriggers([
        parameterizedCron('''
             15 20 * * * %test=true
             05 20 * * * %test=false''')
    ])
])//properties
</code>```

Also please note that there's this open issue, which indicates that for your trigger to register for the scripted, it would need to be run manually at least twice.

ContentLicense: CC BY-SA 4.0

Body:
I switched from declerativ pipeline to scripted pipeline. Everything works fine only  the Parameterized Scheduler Plugin makes problems. If i have one Trigger it works and the pipeline is scheduled. If i add another trigger only the second one works. May be it's a syntax problem but everything i tried doesn't work. Any ideas?

properties([
    parameters([
        booleanParam (defaultValue: true, description: 'test', name: 'test')
    ]),
    pipelineTriggers([
        parameterizedCron('15 20 * * * test=true'),
        parameterizedCron('05 20 * * * test=false')
    ])
])//properties

Body:
according to official documentation your syntax is wrong, you are missing %. Also you can use one multiline parameterizedCron.

pipeline {
    agent any
    parameters {
      string(name: 'PLANET', defaultValue: 'Earth', description: 'Which planet are we on?')
      string(name: 'GREETING', defaultValue: 'Hello', description: 'How shall we greet?')
    }
    triggers {
        cron('* * * * *')
        parameterizedCron('''
# leave spaces where you want them around the parameters. They'll be trimmed.
# we let the build run with the default name
*/2 * * * * %GREETING=Hola;PLANET=Pluto
*/3 * * * * %PLANET=Mars
        ''')
    }
    stages {
        stage('Example') {
            steps {
                echo "${GREETING} ${PLANET}"
                script { currentBuild.description = "${GREETING} ${PLANET}" }
            }
        }
    }
}

So in your case it should be

properties([
    parameters([
        booleanParam (defaultValue: true, description: 'test', name: 'test')
    ]),
    pipelineTriggers([
        parameterizedCron('''
             15 20 * * * %test=true
             05 20 * * * %test=false''')
    ])
])//properties

Also please note that there's this open issue, which indicates that for your trigger to register for the scripted, it would need to be run manually at least twice.


问:
Unable to launch Internet explorer,instead tries to look for opera launcher
When I am trying to launch internet explorer 11,it tries to look for opera launcher and throws a exception as
"Exception Occured:

```<code>org.openqa.selenium.WebDriverException: Could not initialize class com.opera.core.systems.runner.launcher.OperaLauncherRunner
Command duration or timeout: 109 milliseconds
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.7.0_79'"

My hub file is as below:
C:
java -jar C:\Users\Public\Selenium-batch\selenium-server-standalone-2.42.2.jar -role hub -host "10.79.104.5" -port 4444
 and Node is as below:
C:
java -Dwebdriver.ie.driver=C:\Users\Public\Selenium-batch\IEDriverServer.exe  -jar C:\Users\Public\Selenium-batch\selenium-server-standalone-2.42.2.jar -role node -host "10.79.104.5" -hub http://10.79.104.5:4444/grid/register -port 5566 -browser browserName=iexplorer,platform=WINDOWS,maxInstances=1 -browser browserName=firefox,platform=WINDOWS,maxInstances=1 -browser browserName=chrome,platform=WINDOWS,maxInstances=1 -maxSessions=3
</code>```

It was previously working with JAVA 1.7 and a JRE1.8 got installed by mistake and when I uninstalled JRE8 and Restarted my system it is giving this error.

```<code>TestCase ID:174602 and Browser Name is:IE and  Iteration Id: 1
Exception Occured: org.openqa.selenium.WebDriverException: Could not initialize class com.opera.core.systems.runner.launcher.OperaLauncherRunner
Command duration or timeout: 109 milliseconds
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.7.0_79'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
</code>```

答: Problem solved. When I added -Dos.name=windows to my hub and node batch file.Its running fine now.</p>

Body:
When I am trying to launch internet explorer 11,it tries to look for opera launcher and throws a exception as
"Exception Occured:

org.openqa.selenium.WebDriverException: Could not initialize class com.opera.core.systems.runner.launcher.OperaLauncherRunner
Command duration or timeout: 109 milliseconds
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.7.0_79'"

My hub file is as below:
C:
java -jar C:\Users\Public\Selenium-batch\selenium-server-standalone-2.42.2.jar -role hub -host "10.79.104.5" -port 4444
 and Node is as below:
C:
java -Dwebdriver.ie.driver=C:\Users\Public\Selenium-batch\IEDriverServer.exe  -jar C:\Users\Public\Selenium-batch\selenium-server-standalone-2.42.2.jar -role node -host "10.79.104.5" -hub http://10.79.104.5:4444/grid/register -port 5566 -browser browserName=iexplorer,platform=WINDOWS,maxInstances=1 -browser browserName=firefox,platform=WINDOWS,maxInstances=1 -browser browserName=chrome,platform=WINDOWS,maxInstances=1 -maxSessions=3

It was previously working with JAVA 1.7 and a JRE1.8 got installed by mistake and when I uninstalled JRE8 and Restarted my system it is giving this error.

TestCase ID:174602 and Browser Name is:IE and  Iteration Id: 1
Exception Occured: org.openqa.selenium.WebDriverException: Could not initialize class com.opera.core.systems.runner.launcher.OperaLauncherRunner
Command duration or timeout: 109 milliseconds
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.7.0_79'
Driver info: org.openqa.selenium.remote.RemoteWebDriver


问:
Pointer to member function using C++ lambda
I'm trying to find a way to provide pointers to a member functions between different class instances. For the moment I'm able to provide pointers to member function that takes no arguments but cannot manage to do so when the function to point to has an argument.

A sample code to illustrate my problem :

```<code>#include <iostream>

class Event
{
public:
    std::string type;
    Event(std::string type):type(type){}
};

class EventDispatcherBase
{
public:

    void addEventListener(std::function<void(Event &event)> listener)
    {
        Event myEvent("Type of the myEvent object");
        listener(myEvent);
    }
};

class EventDispatcherClass:public EventDispatcherBase
{
public:
    EventDispatcherClass()
    {
        addEventListener([](Event &event){std::cout << event.type << std::endl;});
        //addEventListener([this]{listener(Event event);});
    };

    void listener(Event &event)
    {
        std::cout << event.type << std::endl;
    }
};

int main()
{
    EventDispatcherClass eventDispatcherClass;

    return 0;
}
</code>```

This code works with an anonymous lambda expression and output "Type of the myEvent object" in the console. But if I uncomment the line

```<code>addEventListener([this]{listener(Event event);});
</code>```

in the constructor of the EventDispatcherClass in order to transmit a pointer to the void listener(Event &event) member function, the compiler throw the following error :

no viable conversion from '(lambda at .../main.cpp:27:26)' to
  'std::function'

I don't understand why.

答:
but cannot manage to do so when the function to point to has an argument.

The lambda should take an argument of type Event&, which will be forwarded to the member function inside the lambda. So change it to

```<code>addEventListener([this](Event &event){listener(event);});
//                     ^^^^^^^^^^^^^^
</code>```

LIVE

Body:
I'm trying to find a way to provide pointers to a member functions between different class instances. For the moment I'm able to provide pointers to member function that takes no arguments but cannot manage to do so when the function to point to has an argument.

A sample code to illustrate my problem :

#include <iostream>

class Event
{
public:
    std::string type;
    Event(std::string type):type(type){}
};

class EventDispatcherBase
{
public:

    void addEventListener(std::function<void(Event &event)> listener)
    {
        Event myEvent("Type of the myEvent object");
        listener(myEvent);
    }
};

class EventDispatcherClass:public EventDispatcherBase
{
public:
    EventDispatcherClass()
    {
        addEventListener([](Event &event){std::cout << event.type << std::endl;});
        //addEventListener([this]{listener(Event event);});
    };

    void listener(Event &event)
    {
        std::cout << event.type << std::endl;
    }
};

int main()
{
    EventDispatcherClass eventDispatcherClass;

    return 0;
}

This code works with an anonymous lambda expression and output "Type of the myEvent object" in the console. But if I uncomment the line

addEventListener([this]{listener(Event event);});

in the constructor of the EventDispatcherClass in order to transmit a pointer to the void listener(Event &event) member function, the compiler throw the following error :

no viable conversion from '(lambda at .../main.cpp:27:26)' to
  'std::function'

I don't understand why.

Body:
but cannot manage to do so when the function to point to has an argument.

The lambda should take an argument of type Event&, which will be forwarded to the member function inside the lambda. So change it to

addEventListener([this](Event &event){listener(event);});
//                     ^^^^^^^^^^^^^^

LIVE


问:
Reading web.config value through javascript
I have web.config with the given value:

```<code><appSettings>
        <add key="vDirectory" value="fr" />
        <add key="BookingSummaryPage" value="/pli/forms/BookingSummary.aspx" />
</appSettings>
</code>```

Now I want to read the value of "vDirectory" through java script.

I am using below code:

```<code><script language="javascript" type="text/javascript">

function test()
{
var t='<%=ConfigurationManager.AppSettings("vDirectory").ToString() %>'
alert(t);
}
</script>

<input type="button" value="Click Me" onclick="test();" />
</code>```

The error generated is:

```<code>Error 'System.Configuration.ConfigurationManager.AppSettings' is a 'property' but is used like a 'method'
</code>```

答:
Try this:

ConfigurationManager.AppSettings["vDirectory"].ToString()

Please note that square brackets are used instead of normal brackets.

ContentLicense: CC BY-SA 2.5

Body:
I have web.config with the given value:

<appSettings>
        <add key="vDirectory" value="fr" />
        <add key="BookingSummaryPage" value="/pli/forms/BookingSummary.aspx" />
</appSettings>

Now I want to read the value of "vDirectory" through java script.

I am using below code:

<input type="button" value="Click Me" onclick="test();" />

The error generated is:

Error 'System.Configuration.ConfigurationManager.AppSettings' is a 'property' but is used like a 'method'

ContentLicense: CC BY-SA 3.0


问:
replace values in data-table based on column number and separate index vector
I am given a large data-table and I need to set cells to a fixed value (e.g. 0) based on the column number and an index dependent on the row number.

As an example, I am given a data-table 'dt' full of ones. Additionally, I have a column vector, giving the number of columns (per row) that shall remain unchanged and the remaining ones shall be set to 0.

```<code>dt <- setnames(data.table(matrix(1,nrow=100, ncol=11)),as.character(c(0:10)))

set.seed(1)
index <- sample(c(0:11),100, replace=TRUE)

> dput(index)
c(3L, 4L, 6L, 10L, 2L, 10L, 11L, 7L, 7L, 0L, 2L, 2L, 8L, 4L,
9L, 5L, 8L, 11L, 4L, 9L, 11L, 2L, 7L, 1L, 3L, 4L, 0L, 4L, 10L,
4L, 5L, 7L, 5L, 2L, 9L, 8L, 9L, 1L, 8L, 4L, 9L, 7L, 9L, 6L, 6L,
9L, 0L, 5L, 8L, 8L, 5L, 10L, 5L, 2L, 0L, 1L, 3L, 6L, 7L, 4L,
10L, 3L, 5L, 3L, 7L, 3L, 5L, 9L, 1L, 10L, 4L, 10L, 4L, 4L, 5L,
10L, 10L, 4L, 9L, 11L, 5L, 8L, 4L, 3L, 9L, 2L, 8L, 1L, 2L, 1L,
2L, 0L, 7L, 10L, 9L, 9L, 5L, 4L, 9L, 7L)
</code>```

For example, in the first row, the first three cells remain unchanged and the other ones are set to 0.
As it is a large data-table, I look for an efficient way to do this

答:
An option using Matrix package:

```<code>library(Matrix)
mat <- as.matrix(dt)
mat * as.matrix(sparseMatrix(
    i=rep(seq_along(index), index),
    j=unlist(sapply(index, seq_len)),
    x=1))
</code>```

Or using data.table::set:

```<code>for (j in seq_along(names(dt)))
    set(dt, which(j>index), j, 0)
</code>```

Body:
I am given a large data-table and I need to set cells to a fixed value (e.g. 0) based on the column number and an index dependent on the row number.

As an example, I am given a data-table 'dt' full of ones. Additionally, I have a column vector, giving the number of columns (per row) that shall remain unchanged and the remaining ones shall be set to 0.

dt <- setnames(data.table(matrix(1,nrow=100, ncol=11)),as.character(c(0:10)))

set.seed(1)
index <- sample(c(0:11),100, replace=TRUE)

> dput(index)
c(3L, 4L, 6L, 10L, 2L, 10L, 11L, 7L, 7L, 0L, 2L, 2L, 8L, 4L,
9L, 5L, 8L, 11L, 4L, 9L, 11L, 2L, 7L, 1L, 3L, 4L, 0L, 4L, 10L,
4L, 5L, 7L, 5L, 2L, 9L, 8L, 9L, 1L, 8L, 4L, 9L, 7L, 9L, 6L, 6L,
9L, 0L, 5L, 8L, 8L, 5L, 10L, 5L, 2L, 0L, 1L, 3L, 6L, 7L, 4L,
10L, 3L, 5L, 3L, 7L, 3L, 5L, 9L, 1L, 10L, 4L, 10L, 4L, 4L, 5L,
10L, 10L, 4L, 9L, 11L, 5L, 8L, 4L, 3L, 9L, 2L, 8L, 1L, 2L, 1L,
2L, 0L, 7L, 10L, 9L, 9L, 5L, 4L, 9L, 7L)

For example, in the first row, the first three cells remain unchanged and the other ones are set to 0.
As it is a large data-table, I look for an efficient way to do this

Body:
An option using Matrix package:

library(Matrix)
mat <- as.matrix(dt)
mat * as.matrix(sparseMatrix(
    i=rep(seq_along(index), index),
    j=unlist(sapply(index, seq_len)),
    x=1))

Or using data.table::set:

for (j in seq_along(names(dt)))
    set(dt, which(j>index), j, 0)


问:
Spring JPA composite PK with one auto-incremented
I'm trying to persist an entity with a composite primary key, one of which should be auto-incremented, using Spring Boot 2.1.2.RELEASE + JPA (using starters) and MySQL (InnoDB). I have an abstract class with 2 non-abstract subclasses and I'm using single table strategy for inheritance.

I've been looking around how to go about accomplishing this but every post that seems to be looking for the same as me ends up without an answer (example).

My current setup looks like this (setters, getters and constructors omitted for clarity).

```<code>@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@IdClass(MyEntityPK.class)
public abstract class MyEntity {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    long pk1; //Should be auto-incremented

    @Id
    OffsetDateTime pk2;

    //More fields...
</code>```

public class MyEntityPK implements Serializable {
   private static final long serialVersionUID = 1L;

   long pk1;
   OffsetDateTime pk2;
}
```

<pre class="lang-java prettyprint-override"><code>@Repository
public interface MyEntityRepository extends CrudRepository<MyEntity, MyEntityPK> {
   //Some methods like save().
}

</code>```

The first problem I found was with the table generation. MySQL allows creating the PK if it's declared like

```<code>PRIMARY KEY (pk1, pk2)
</code>```

but not in the different order

```<code>PRIMARY KEY (pk2, pk1)
</code>```

When creating the table, Hibernate uses the second one, and thus failing. Also tried to change fields order but to no avail. I think this might be an issue with Hibernate, but I'm not sure. Can anyone confirm? Anyway, I solved that by creating the DDL script manually and disabling automatic DDL by Hibernate.

The next issue, for which I did not find an answer, was that the entities were saved correctly in the table, but the id returned by the save method of the repository was always 0. I was manually setting pk2 before saving, while leaving pk1 to be completed by the DB.

```<code>entity.setPk2(OffsetDateTime.now());
Entity savedEntity = repository.save(entity); //savedEntity has id 1 in table but 0 in code
</code>```

While debugging, I arrived at this isNew() method. It turns out it was returning false because MyEntityPK was different from null (I had set pk2). This of course is not what I expected, since I actually am saving a new entity, given that my PK is composite and I left one field blank. So, I also think this may be a bug. There are some classes that override isNew() method, but it seems they are not being used.

Am I doing something wrong or is this a bug? Help appreciated :)

答:
@GeneratedValue(strategy = GenerationType.IDENTITY) on @EmbededId or @IdClass is not supported.

Here is a bug related exactly to your request which was rejected by hibernate https://hibernate.atlassian.net/browse/ANN-268

Here is another much more recent bug reporteing the same. Notice here Vlad Mihalcea comment:

This is not a Blocker, it's merely a Major issue. For instance, the
  JPA spec does not even say if generated identifiers are allowed in a
  Composite Identifier.

Anyway, this only works as @IdClass with sequence-based identifiers,
  as explained in this article.

https://hibernate.atlassian.net/browse/HHH-9662

The article in the quotation explains how to map @GeneratedValue(strategy = GenerationType.SEQUENCE) on composite.

Body:
I'm trying to persist an entity with a composite primary key, one of which should be auto-incremented, using Spring Boot 2.1.2.RELEASE + JPA (using starters) and MySQL (InnoDB). I have an abstract class with 2 non-abstract subclasses and I'm using single table strategy for inheritance.

I've been looking around how to go about accomplishing this but every post that seems to be looking for the same as me ends up without an answer (example).

My current setup looks like this (setters, getters and constructors omitted for clarity).

@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@IdClass(MyEntityPK.class)
public abstract class MyEntity {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    long pk1; //Should be auto-incremented

    @Id
    OffsetDateTime pk2;

    //More fields...

public class MyEntityPK implements Serializable {
   private static final long serialVersionUID = 1L;

   long pk1;
   OffsetDateTime pk2;
}

@Repository
public interface MyEntityRepository extends CrudRepository<MyEntity, MyEntityPK> {
   //Some methods like save().
}

The first problem I found was with the table generation. MySQL allows creating the PK if it's declared like

PRIMARY KEY (pk1, pk2)

but not in the different order

PRIMARY KEY (pk2, pk1)

When creating the table, Hibernate uses the second one, and thus failing. Also tried to change fields order but to no avail. I think this might be an issue with Hibernate, but I'm not sure. Can anyone confirm? Anyway, I solved that by creating the DDL script manually and disabling automatic DDL by Hibernate.

The next issue, for which I did not find an answer, was that the entities were saved correctly in the table, but the id returned by the save method of the repository was always 0. I was manually setting pk2 before saving, while leaving pk1 to be completed by the DB.

entity.setPk2(OffsetDateTime.now());
Entity savedEntity = repository.save(entity); //savedEntity has id 1 in table but 0 in code

While debugging, I arrived at this isNew() method. It turns out it was returning false because MyEntityPK was different from null (I had set pk2). This of course is not what I expected, since I actually am saving a new entity, given that my PK is composite and I left one field blank. So, I also think this may be a bug. There are some classes that override isNew() method, but it seems they are not being used.

Am I doing something wrong or is this a bug? Help appreciated :)


问:
Laravel - Pass String Parameter from View to Controller
I have these tables:

```<code>users (User): username,plan
billings: (Billings): email,amount,plan
</code>```

The issue I have is that in users table, plan is interger (1=daily, 2=Weekly, 3=monthly) while in billings table, plan is varchar(daily, weekly,monthly).I have created billing controller and view using the Billings Model. I want to relate the two fields.

This is the working code that creates billing:

Controller

```<code>public function usersBilling()
{
    $billings = DB::table("billings")
        ->select("billings.plan", DB::raw("COUNT(billings.plan) as total_plans") ,DB::raw("SUM(billings.amount) as total_amount"))
        ->join("users","users.email","=","billings.email")
        ->groupBy("billings.plan")
        ->orderByRaw('billings.plan ASC')
        ->paginate(15);

    return view('report.usersBilling', compact('billings'));
}
</code>```

report/usersBilling.blade.php

```<code><td><a href="{{ route('report.showBillingDetail',$billing->plan) }}">{{ $billing->plan }}</a></td>
<td>{{ $billing->total_plans }}</td>
<td>{{ $billing->total_amount }}</td>
</code>```

Here is the Controller I want to complete

```<code>public function showBillingDetail(Request $request,$billingtype)
{
    $user= User::findOrFail($billingtype);

    return view('report.showBillingDetail', compact('user'));
}
</code>```

I want to complete this.

When I click on the plan through the link in:

```<code>href="{{ route('report.showBillingDetail',$billing->plan) }}"
</code>```

It should display all users with that plan. Since plan in users table is integer (1,2,3) and plan in billings is varchar (daily, weekly, monthly), how do I write a query in the UserController that will receive the plan parameter from the billing view and relate it with plan in users table and select all fields in the users table based on the parameter. 1=daily, 2=weekly, 3=monthly

答:
Ideally you have to use Eloquent Model to query on database. It will provide you flexibility to manage these types of cases.

But if you are preferring DB::table() then you can add one more select field which will identify you plan like daily, weekly or monthly.

```<code>public function usersBilling()
{
    $billings = DB::table("billings")
        ->select("billings.plan", DB::raw("COUNT(billings.plan) as total_plans") ,DB::raw("SUM(billings.amount) as total_amount", DB::raw("IF(billings.plan == 1), 'daily", IF(billings.plan == 2), 'weekly', 'monthly')))
        ->join("users","users.email","=","billings.email")
        ->groupBy("billings.plan")
        ->orderByRaw('billings.plan ASC')
        ->paginate(15);

    return view('report.usersBilling', compact('billings'));
}
</code>```

I think this will help you.

Body:
I have these tables:

users (User): username,plan
billings: (Billings): email,amount,plan

The issue I have is that in users table, plan is interger (1=daily, 2=Weekly, 3=monthly) while in billings table, plan is varchar(daily, weekly,monthly).I have created billing controller and view using the Billings Model. I want to relate the two fields.

This is the working code that creates billing:

Controller

public function usersBilling()
{
    $billings = DB::table("billings")
        ->select("billings.plan", DB::raw("COUNT(billings.plan) as total_plans") ,DB::raw("SUM(billings.amount) as total_amount"))
        ->join("users","users.email","=","billings.email")
        ->groupBy("billings.plan")
        ->orderByRaw('billings.plan ASC')
        ->paginate(15);

    return view('report.usersBilling', compact('billings'));
}

report/usersBilling.blade.php

plan) }}">{{ $billing->plan }}
{{ $billing->total_plans }}
{{ $billing->total_amount }}

Here is the Controller I want to complete

public function showBillingDetail(Request $request,$billingtype)
{
    $user= User::findOrFail($billingtype);

    return view('report.showBillingDetail', compact('user'));
}

I want to complete this.

When I click on the plan through the link in:

href="{{ route('report.showBillingDetail',$billing->plan) }}"

It should display all users with that plan. Since plan in users table is integer (1,2,3) and plan in billings is varchar (daily, weekly, monthly), how do I write a query in the UserController that will receive the plan parameter from the billing view and relate it with plan in users table and select all fields in the users table based on the parameter. 1=daily, 2=weekly, 3=monthly

Body:
Ideally you have to use Eloquent Model to query on database. It will provide you flexibility to manage these types of cases.

But if you are preferring DB::table() then you can add one more select field which will identify you plan like daily, weekly or monthly.

public function usersBilling()
{
    $billings = DB::table("billings")
        ->select("billings.plan", DB::raw("COUNT(billings.plan) as total_plans") ,DB::raw("SUM(billings.amount) as total_amount", DB::raw("IF(billings.plan == 1), 'daily", IF(billings.plan == 2), 'weekly', 'monthly')))
        ->join("users","users.email","=","billings.email")
        ->groupBy("billings.plan")
        ->orderByRaw('billings.plan ASC')
        ->paginate(15);

    return view('report.usersBilling', compact('billings'));
}

I think this will help you.


问:
Unknown issue when trying to make a dropdown in html and php
Making a new tool and require a dropdown menu but it doesn't seem to work the way I have coded it.

Not sure exactly what the problem is. Have researched online but I haven't been able to figure it out.

```<code>if(!isset($_POST["ReasonList"]))
 {
  $error .= '<p><label class="text-danger">Please select a reason</label></p>';
 }
</code>```

```<code><div class="form-group">
<label>Select Reason for Request</label>
<select id="ReasonList" name="ReasonList" class="form-control" value="<?php echo $ReasonList; ?>" />

  <option value = "">Select...</option>
  <option value = "1">Original Engineer has left the company</option>
  <option value = "2">Actively involved in field work on customer site</option>
  <option value = "3">No capacity due to customer mandated deadlines</option>
  <option value = "4">Exception request by manager</option>
</select>
</div>
</code>```

If option is selected then able to submit the form. If option is not selected it will give the error in the if statement - Please select a reason

答:
See the corrected <select> element, and how a bit of code indentation make the HTML easier to read and debug.

```<code><div class="form-group">
    <label>Select Reason for Request</label>
    <select id="ReasonList" name="ReasonList" class="form-control">
        <option value = "">Select...</option>
        <option value = "1">Original Engineer has left the company</option>
        <option value = "2">Actively involved in field work on customer site</option>
        <option value = "3">No capacity due to customer mandated deadlines</option>
        <option value = "4">Exception request by manager</option>
    </select>
</div>
</code>```

The <select> element does not have a value property and you accidentally closed the <select> before the name attribute.

Body:
Making a new tool and require a dropdown menu but it doesn't seem to work the way I have coded it.

Not sure exactly what the problem is. Have researched online but I haven't been able to figure it out.

if(!isset($_POST["ReasonList"]))
 {
  $error .= '
Please select a reason
';
 }

Select Reason for Request
<select id="ReasonList" name="ReasonList" class="form-control" value="<?php echo $ReasonList; ?>" />

  <option value = "">Select...</option>
  <option value = "1">Original Engineer has left the company</option>
  <option value = "2">Actively involved in field work on customer site</option>
  <option value = "3">No capacity due to customer mandated deadlines</option>
  <option value = "4">Exception request by manager</option>
</select>

If option is selected then able to submit the form. If option is not selected it will give the error in the if statement - Please select a reason

Body:
See the corrected <select> element, and how a bit of code indentation make the HTML easier to read and debug.

<div class="form-group">
    <label>Select Reason for Request</label>
    <select id="ReasonList" name="ReasonList" class="form-control">
        <option value = "">Select...</option>
        <option value = "1">Original Engineer has left the company</option>
        <option value = "2">Actively involved in field work on customer site</option>
        <option value = "3">No capacity due to customer mandated deadlines</option>
        <option value = "4">Exception request by manager</option>
    </select>
</div>

The <select> element does not have a value property and you accidentally closed the <select> before the name attribute.


问:
How To make 2 or more tables From one JSON data
I am working on creating dynamic HTML table from JSON Data, I have already created the table dynamically but now I have to Change it with new Requirement

What I am doing

I have array of objects from which i am creating the table and spiting the table into four columns by dividing the length of JSON to 4

My table is rendering perfectly into 4 columns

What I am trying to Do

I want to show only 5 Rows in a single go then reloads the div and render the next five rows in same dive and so on until all data gets render

Currently I have 68 total data so i am populating it as 17 rows of 4 columns

Now on one go when page lodes I want to show 5 rows then after 5 seconds Next 5 rows in same div

In simple terms I want to split my JSON data into part of 5-5 rows and show only 5 rows at once then next five after 5 seconds

Spiting the Table into Four Columns I have done already,now just want to Show only five rows at a time

I am lacking with idea or approach how to do this, How can i divide my JSON in five-five rows and show them at each time interval of 5 seconds

What I am have done

var tableValue = [{
  "Item Name": "MANCHOW  V SOUP",
  "SellingPrice": 100
}, {
  "Item Name": "MANCHOW NV SOUP ",
  "SellingPrice": 125
}, {
  "Item Name": "CEASER SALAD V",
  "SellingPrice": 175
}, {
  "Item Name": "CEASER SALAD NV",
  "SellingPrice": 230
}, {
  "Item Name": "GAMBUS REBOZADAS",
  "SellingPrice": 350
}, {
  "Item Name": "PANCO FISH FINGER",
  "SellingPrice": 270
}, {
  "Item Name": "MUSHROOM DUPLEX",
  "SellingPrice": 160
}, {
  "Item Name": "FRENCH FRIES",
  "SellingPrice": 99
}, {
  "Item Name": "HONEY GARLIC PRAWN",
  "SellingPrice": 350
}, {
  "Item Name": "CHICKEN MANCHURIAN",
  "SellingPrice": 180
}, {
  "Item Name": "MUSHROOM CHILLY",
  "SellingPrice": 120
}, {
  "Item Name": "SALT N PEPPER BABY CORN",
  "SellingPrice": 120
}, {
  "Item Name": "SOUTHERN STYLE CHICKEN",
  "SellingPrice": 210
}, {
  "Item Name": "PANEER NAGGETS",
  "SellingPrice": 210
}, {
  "Item Name": "HARA BHARA KEBAB",
  "SellingPrice": 160
}, {
  "Item Name": "CHICKEN TIKKA",
  "SellingPrice": 210
}, {
  "Item Name": "KALMI KEBAB",
  "SellingPrice": 250
}, {
  "Item Name": "PIZZA MARGARITTA",
  "SellingPrice": 200
}, {
  "Item Name": "PIZZA VEG FARMHOUSE",
  "SellingPrice": 200
}, {
  "Item Name": "BBQ CHICKEN PIZZA",
  "SellingPrice": 225
}, {
  "Item Name": "CHICKEN TIKKA PIZZA",
  "SellingPrice": 225
}, {
  "Item Name": "PESTO SAUCE",
  "SellingPrice": 175
}, {
  "Item Name": "ARABIATA",
  "SellingPrice": 160
}, {
  "Item Name": "PINK SAUCE",
  "SellingPrice": 160
}, {
  "Item Name": "GARBANZO BEAN SALAD",
  "SellingPrice": 90
}, {
  "Item Name": "MASALA PAPAD",
  "SellingPrice": 50
}, {
  "Item Name": "PEANUT MASALA",
  "SellingPrice": 60
}, {
  "Item Name": "GAJAR KA HALWA",
  "SellingPrice": 90
}, {
  "Item Name": "WATERMELON MARTINI",
  "SellingPrice": 281
}, {
  "Item Name": "Kiwi martini",
  "SellingPrice": 281
}, {
  "Item Name": " Apple gin",
  "SellingPrice": 225
}, {
  "Item Name": "Cucumber  cooler ",
  "SellingPrice": 281
}, {
  "Item Name": "Martini",
  "SellingPrice": 225
}, {
  "Item Name": "Pink lady",
  "SellingPrice": 225
}, {
  "Item Name": " Bloody marry",
  "SellingPrice": 281
}, {
  "Item Name": "Cosmopolitan",
  "SellingPrice": 281
}, {
  "Item Name": "Sex on the beach",
  "SellingPrice": 281
}, {
  "Item Name": "Bull frog",
  "SellingPrice": 506
}, {
  "Item Name": "Long  island iced tea ",
  "SellingPrice": 393
}, {
  "Item Name": "Pinacolada",
  "SellingPrice": 225
}, {
  "Item Name": "Daiquiri",
  "SellingPrice": 225
}, {
  "Item Name": "Mojito ",
  "SellingPrice": 281
}, {
  "Item Name": "Whisky sour",
  "SellingPrice": 281
}, {
  "Item Name": "Hot toddy",
  "SellingPrice": 225
}, {
  "Item Name": "Margarita",
  "SellingPrice": 337
}, {
  "Item Name": "Tequila sunrise",
  "SellingPrice": 337
}, {
  "Item Name": "Red sangria",
  "SellingPrice": 225
}, {
  "Item Name": "White sangria",
  "SellingPrice": 247
}, {
  "Item Name": "Rose sangria",
  "SellingPrice": 247
}, {
  "Item Name": "By chance special ",
  "SellingPrice": 168
}, {
  "Item Name": "Made in heaven",
  "SellingPrice": 168
}, {
  "Item Name": "Strawberry delight",
  "SellingPrice": 168
}, {
  "Item Name": "DRAGON",
  "SellingPrice": 168
}, {
  "Item Name": "Mangochil ",
  "SellingPrice": 168
}, {
  "Item Name": "Cucumber cola",
  "SellingPrice": 168
}, {
  "Item Name": "Virgin mojito",
  "SellingPrice": 168
}, {
  "Item Name": "Virgin mary",
  "SellingPrice": 168
}, {
  "Item Name": "Virgin pinacolada",
  "SellingPrice": 168
}, {
  "Item Name": "CORONA",
  "SellingPrice": 438
}, {
  "Item Name": "CRAFT BEERS",
  "SellingPrice": 337
}, {
  "Item Name": "BIRA WHITE 330",
  "SellingPrice": 157
}, {
  "Item Name": "BIRA BLONDE 330",
  "SellingPrice": 135
}, {
  "Item Name": "BIRA STRONG 650",
  "SellingPrice": 213
}, {
  "Item Name": "KINGFISHER PREMIUM 330",
  "SellingPrice": 123
}, {
  "Item Name": "KINGFISHER PREMIUM 650",
  "SellingPrice": 202
}, {
  "Item Name": "KINGFISHER STRONG 330",
  "SellingPrice": 135
}, {
  "Item Name": "KINGFISHER STRONG 650",
  "SellingPrice": 213
}, {
  "Item Name": "KINGFISHER ULTRA 330",
  "SellingPrice": 146
}, {
  "Item Name": "KINGFISHER ULTRA 650",
  "SellingPrice": 281
}, {
  "Item Name": "KINGFISHER ULTRA MAX 330",
  "SellingPrice": 146
}, {
  "Item Name": "KINGFISHER ULTRA MAX 650",
  "SellingPrice": 281
}, {
  "Item Name": "BUDWIESER 330",
  "SellingPrice": 146
}, {
  "Item Name": "BUDWIESER 650",
  "SellingPrice": 270
}, {
  "Item Name": "BUDWIESER MAGNUM 330",
  "SellingPrice": 168
}, {
  "Item Name": "BUDWIESER MAGNUM 650",
  "SellingPrice": 281
}, {
  "Item Name": "TUBORG 330",
  "SellingPrice": 123
}, {
  "Item Name": "TUBORG 650",
  "SellingPrice": 191
}, {
  "Item Name": "TUBORG STRONG 330",
  "SellingPrice": 123
}, {
  "Item Name": "TUBORG STRONG 650",
  "SellingPrice": 213
}, {
  "Item Name": "CRANBERRY ",
  "SellingPrice": 157
}, {
  "Item Name": "ORANGE",
  "SellingPrice": 157
}, {
  "Item Name": "JAMICAN",
  "SellingPrice": 157
}, {
  "Item Name": "BLACK BERRY",
  "SellingPrice": 157
}, {
  "Item Name": "BLUE BERRY",
  "SellingPrice": 157
}, {
  "Item Name": "MOET CHANDON",
  "SellingPrice": 7875
}, {
  "Item Name": "SULA BRUT",
  "SellingPrice": 1687
}, {
  "Item Name": "MATEUS ROSE",
  "SellingPrice": 2137
}, {
  "Item Name": "HARDYS SIRAZ CABERNET 750",
  "SellingPrice": 1890
}, {
  "Item Name": "HARDYS SIRAZ CABERNET BY GLASS",
  "SellingPrice": 382
}, {
  "Item Name": "JACOB CREEK SIRAZ 750",
  "SellingPrice": 1800
}, {
  "Item Name": "JACOB CREEK SIRAZ BY GLASS",
  "SellingPrice": 360
}, {
  "Item Name": "BIG BANAYAN CHENNIN BLANC 750",
  "SellingPrice": 990
}, {
  "Item Name": "BIG BANAYAN CHENNIN BLANC BY GLASS",
  "SellingPrice": 202
}, {
  "Item Name": "SULA CHENIN BLANC 750 ",
  "SellingPrice": 1293
}, {
  "Item Name": "SULA CHENIN BLANC BY GLASS",
  "SellingPrice": 258
}, {
  "Item Name": "FOUR SEAZON CLASSIC CHENNIN BLANC 750",
  "SellingPrice": 1125
}, {
  "Item Name": "FOUR SEAZON CLASSIC CHENNIN BLANC BY GLASS",
  "SellingPrice": 225
}, {
  "Item Name": "BIG BANAYAN CARBINET SAUVIGNON 750",
  "SellingPrice": 1125
}, {
  "Item Name": "BIG BANAYAN CARBINET SAUVIGNON BY GLASS",
  "SellingPrice": 225
}, {
  "Item Name": "SULA SATORI MERLOT 750",
  "SellingPrice": 1237
}, {
  "Item Name": "SULA SATORI MERLOT BY GLASS",
  "SellingPrice": 247
}, {
  "Item Name": "GROVERS LA RESERVE 750",
  "SellingPrice": 1800
}, {
  "Item Name": "GROVERS LA RESERVE 100",
  "SellingPrice": 360
}, {
  "Item Name": "GLENFIDDICH 12 YEARS 700 ",
  "SellingPrice": 9225
}, {
  "Item Name": "GLENFIDDICH 12 YEARS 30",
  "SellingPrice": 405
}, {
  "Item Name": "TALISKER 750",
  "SellingPrice": 8775
}, {
  "Item Name": "TALISKER 30",
  "SellingPrice": 360
}, {
  "Item Name": "GLENNLIVET 750",
  "SellingPrice": 8887
}, {
  "Item Name": "GLENNLIVET 30",
  "SellingPrice": 360
}, {
  "Item Name": "THE SINGLETON 750",
  "SellingPrice": 7942
}, {
  "Item Name": "THE SINGLETON 30",
  "SellingPrice": 326
}, {
  "Item Name": "AMRUT FUSION 750",
  "SellingPrice": 5062
}, {
  "Item Name": "AMRUT FUSION 30",
  "SellingPrice": 202
}, {
  "Item Name": "JACK DANIELS 750",
  "SellingPrice": 7312
}, {
  "Item Name": "JACK DANIELS 30",
  "SellingPrice": 292
}, {
  "Item Name": "JIM BEAM WHITE 750",
  "SellingPrice": 4095
}, {
  "Item Name": "JIM BEAM WHITE 30",
  "SellingPrice": 168
}, {
  "Item Name": "JAMESON 750",
  "SellingPrice": 4950
}, {
  "Item Name": "JAMESON 30",
  "SellingPrice": 202
}, {
  "Item Name": "JW BLACK LABEL 750",
  "SellingPrice": 8212
}, {
  "Item Name": "JW BLACK LABEL 200",
  "SellingPrice": 2925
}, {
  "Item Name": "JW BLACK LABEL 30",
  "SellingPrice": 337
}, {
  "Item Name": "JW RED LABEL 200",
  "SellingPrice": 1158
}, {
  "Item Name": "BALLENTINSE FINEST BLENDED 750",
  "SellingPrice": 4545
}, {
  "Item Name": "BALLENTINSE FINEST BLENDED 30",
  "SellingPrice": 180
}, {
  "Item Name": "BLACK \u0026 WHITE 375",
  "SellingPrice": 1575
}, {
  "Item Name": "BLACK \u0026 WHITE 180",
  "SellingPrice": 787
}, {
  "Item Name": "BLACK \u0026 WHITE 60",
  "SellingPrice": 258
}, {
  "Item Name": "BLACK \u0026 WHITE 30",
  "SellingPrice": 135
}, {
  "Item Name": "100 PIPERS 180",
  "SellingPrice": 787
}, {
  "Item Name": "100 PIPERS 60",
  "SellingPrice": 258
}, {
  "Item Name": "100 PIPERS 30",
  "SellingPrice": 135
}, {
  "Item Name": "VAT 69 180",
  "SellingPrice": 675
}, {
  "Item Name": "VAT 69 60",
  "SellingPrice": 225
}, {
  "Item Name": "VAT 69 30",
  "SellingPrice": 112
}, {
  "Item Name": "TEACHERS HIGHLAND 180",
  "SellingPrice": 787
}, {
  "Item Name": "TEACHERS HIGHLAND 60",
  "SellingPrice": 258
}, {
  "Item Name": "TEACHERS HIGHLAND 30",
  "SellingPrice": 135
}, {
  "Item Name": "TEACHERS 50 60",
  "SellingPrice": 393
}, {
  "Item Name": "TEACHERS 50 30",
  "SellingPrice": 202
}, {
  "Item Name": "BLACK DOG TRIPPLE GOLD 180",
  "SellingPrice": 1215
}, {
  "Item Name": "BLACK DOG TRIPPLE GOLD 30",
  "SellingPrice": 213
}, {
  "Item Name": "BLACK DOG 8 YEARS 180",
  "SellingPrice": 731
}, {
  "Item Name": "BLACK DOG 8 YEARS 60",
  "SellingPrice": 247
}, {
  "Item Name": "BLACK DOG 8 YEARS 30",
  "SellingPrice": 123
}, {
  "Item Name": "BLENDERS PRIDE 750",
  "SellingPrice": 2283
}, {
  "Item Name": "BLENDERS PRIDE 375",
  "SellingPrice": 1147
}, {
  "Item Name": "BLENDERS PRIDE 180",
  "SellingPrice": 573
}, {
  "Item Name": "BLENDERS PRIDE 60",
  "SellingPrice": 191
}, {
  "Item Name": "BLENDERS PRIDE 30",
  "SellingPrice": 90
}, {
  "Item Name": "SIGNATURE 180",
  "SellingPrice": 450
}, {
  "Item Name": "SIGNATURE 60",
  "SellingPrice": 168
}, {
  "Item Name": "SIGNATURE 30",
  "SellingPrice": 90
}, {
  "Item Name": "GREY GOOSE 750",
  "SellingPrice": 8190
}, {
  "Item Name": "GREY GOOSE 30",
  "SellingPrice": 326
}, {
  "Item Name": "BELVEDERE 700",
  "SellingPrice": 8122
}, {
  "Item Name": "BELVEDERE 30",
  "SellingPrice": 360
}, {
  "Item Name": "CIROC 750",
  "SellingPrice": 7425
}, {
  "Item Name": "CIROC 30",
  "SellingPrice": 303
}, {
  "Item Name": "ABSOLUT 750",
  "SellingPrice": 4556
}, {
  "Item Name": "ABSOLUT 30",
  "SellingPrice": 191
}, {
  "Item Name": "SMIRNOFF RED 180",
  "SellingPrice": 551
}, {
  "Item Name": "SMIRNOFF RED 60",
  "SellingPrice": 202
}, {
  "Item Name": "SMIRNOFF RED30",
  "SellingPrice": 101
}, {
  "Item Name": "SMIRNOFF ORANGE 180",
  "SellingPrice": 551
}, {
  "Item Name": "SMIRNOFF ORANGE 60",
  "SellingPrice": 202
}, {
  "Item Name": "SMINOFF ORANGE30",
  "SellingPrice": 101
}, {
  "Item Name": "SMIRNOFF GREEN APPLE 180",
  "SellingPrice": 551
}, {
  "Item Name": "SMIRNOFF GREEN APPLE 60",
  "SellingPrice": 202
}, {
  "Item Name": "SMIRNOFF GREEN APPLE30",
  "SellingPrice": 101
}, {
  "Item Name": "BOMBAY SAPHIRE 750",
  "SellingPrice": 4725
}, {
  "Item Name": "BOMBAY SAPHIRE 30",
  "SellingPrice": 191
}, {
  "Item Name": "BLUE RIBBAND 750",
  "SellingPrice": 877
}, {
  "Item Name": "BLUE RIBBAND 60",
  "SellingPrice": 78
}, {
  "Item Name": "BACCARDI WHITE 750",
  "SellingPrice": 2418
}, {
  "Item Name": "BACCARDI WHITE 180",
  "SellingPrice": 585
}, {
  "Item Name": "BACCARDI WHITE 60",
  "SellingPrice": 202
}, {
  "Item Name": "BACCARDI WHITE 30",
  "SellingPrice": 101
}, {
  "Item Name": "BACCARDI LEMON 180",
  "SellingPrice": 585
}, {
  "Item Name": "BACCARDI LEMON 60",
  "SellingPrice": 202
}, {
  "Item Name": "BACCARDI LEMON 30",
  "SellingPrice": 101
}, {
  "Item Name": "BACCARDI ORANGE 180",
  "SellingPrice": 585
}, {
  "Item Name": "BACCARDI ORANGE 60",
  "SellingPrice": 202
}, {
  "Item Name": "BACCARDI LEMON 30",
  "SellingPrice": 101
}, {
  "Item Name": "BACCARDI BLACK 180",
  "SellingPrice": 393
}, {
  "Item Name": "BACCARDI BLACK 30",
  "SellingPrice": 67
}, {
  "Item Name": "BACCARDI GOLD 180",
  "SellingPrice": 585
}, {
  "Item Name": "BACCARDI GOLD30",
  "SellingPrice": 101
}, {
  "Item Name": "OLD MONK 180",
  "SellingPrice": 225
}, {
  "Item Name": "OLD MONK 90",
  "SellingPrice": 168
}, {
  "Item Name": "OLD MONK 60",
  "SellingPrice": 90
}, {
  "Item Name": "OLD MONK 30 ",
  "SellingPrice": 45
}, {
  "Item Name": "DON ANGEL 750",
  "SellingPrice": 4668
}, {
  "Item Name": "DON ANGEL 30",
  "SellingPrice": 191
}, {
  "Item Name": "SAUZA SILVER 700",
  "SellingPrice": 6153
}, {
  "Item Name": "SAUZA SILVER 30",
  "SellingPrice": 270
}, {
  "Item Name": "JAGERBOMB",
  "SellingPrice": 506
}, {
  "Item Name": "KAMAKAZI",
  "SellingPrice": 168
}, {
  "Item Name": "JAGERMASTER",
  "SellingPrice": 303
}, {
  "Item Name": "COINTTRAEU",
  "SellingPrice": 303
}, {
  "Item Name": "SAMBUCA",
  "SellingPrice": 258
}, {
  "Item Name": "KHALUA",
  "SellingPrice": 168
}, {
  "Item Name": "MARTINI BLANCO",
  "SellingPrice": 90
}, {
  "Item Name": "MARTINI ROSSO",
  "SellingPrice": 90
}, {
  "Item Name": "HENESSY VS 700",
  "SellingPrice": 7875
}, {
  "Item Name": "HENESSY VS 30",
  "SellingPrice": 348
}, {
  "Item Name": "MORPHEUS 750",
  "SellingPrice": 2182
}, {
  "Item Name": "MORPHEUS 180",
  "SellingPrice": 540
}, {
  "Item Name": "MORPHEUS 60",
  "SellingPrice": 191
}, {
  "Item Name": "MORPHEUS 30",
  "SellingPrice": 101
}, {
  "Item Name": "MANSION HOUSE 180",
  "SellingPrice": 292
}, {
  "Item Name": "MANSION HOUSE 90",
  "SellingPrice": 168
}, {
  "Item Name": "MANSION HOUSE 60",
  "SellingPrice": 90
}, {
  "Item Name": "MC BRANDY 60",
  "SellingPrice": 90
}, {
  "Item Name": "RED BULL ",
  "SellingPrice": 157
}, {
  "Item Name": "COKE",
  "SellingPrice": 45
}, {
  "Item Name": "SPRITE",
  "SellingPrice": 45
}, {
  "Item Name": "SODA",
  "SellingPrice": 33
}, {
  "Item Name": "DIET COKE",
  "SellingPrice": 56
}, {
  "Item Name": "TONIC WATER",
  "SellingPrice": 67
}, {
  "Item Name": "GINGER ALE",
  "SellingPrice": 67
}, {
  "Item Name": "LIME SODA",
  "SellingPrice": 45
}, {
  "Item Name": "LIME WATER",
  "SellingPrice": 45
}, {
  "Item Name": "PACKEGED WATER 1L",
  "SellingPrice": 39
}, {
  "Item Name": "MANSION HOUSE 650",
  "SellingPrice": 900
}, {
  "Item Name": "Chole Kulche",
  "SellingPrice": 80
}, {
  "Item Name": "Butter Nan",
  "SellingPrice": 65
}, {
  "Item Name": "Dhai",
  "SellingPrice": 20
}, {
  "Item Name": "Rice",
  "SellingPrice": 55
}, {
  "Item Name": "Plain rice",
  "SellingPrice": 30
}, {
  "Item Name": "MANSION HOUSE 650",
  "SellingPrice": 900
}, {
  "Item Name": "Chole Kulche",
  "SellingPrice": 80
}, {
  "Item Name": "Butter Nan",
  "SellingPrice": 65
}, {
  "Item Name": "Dhai",
  "SellingPrice": 20
}, {
  "Item Name": "Rice",
  "SellingPrice": 55
}, {
  "Item Name": "Plain rice",
  "SellingPrice": 30
}]

myFun();
window.setInterval(showRows, 5000);
showRows();

function myFun() {
  addTable(tableValue);
}

function showRows() {
  $(".hidden:lt(10)").removeClass("hidden");
}

function addTable(tableValue) {
  var $tbl = $("
", {
      "class": "table"
    }),

    $tb = $("
"),
    $trh = $("
");

  var split = Math.round(tableValue.length / 4);
  for (i = 0; i < split; i++) {
    $tr = $("
", {
      class: "hidden"
    });
    for (j = 0; j < 4; j++) {
      $.each(tableValue[split * j + i], function(key, value) {

        $("", {
          "class": "text-left color" + (j + 1)
        }).html(value).appendTo($tr);
      });
    }
    $tr.appendTo($tb);
  }
  $tbl.append($tb);
  $("#DisplayTable").html($tbl);
}```
<pre class="snippet-code-css lang-css prettyprint-override"><code>tbody>tr>td {
  white-space: nowrap;
  border-collapse: collapse;
  font-family: Verdana;
  font-size: 8pt;
  font-weight: bold;
  white-space: nowrap;
}

.color1 {
  background: #4AD184;
}

.color2 {
  background: #EA69EF;
}

.color3 {
  background: #E1A558;
}

.color4 {
  background: #F4F065;
}</code>```

<link rel="stylesheet" href="//stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css">

```

Edit
I have tried @Void's solution but that is not removing the hidden class,when I inspect the element then there is no class applied to tr it is showing as class=""

答:
You may use Array.prototype.slice() to extract portion of the array and render that into html:

//source data sample
const tableValue=[{"Item Name":"MANCHOW  V SOUP","SellingPrice":100},{"Item Name":"MANCHOW NV SOUP ","SellingPrice":125},{"Item Name":"CEASER SALAD V","SellingPrice":175},{"Item Name":"CEASER SALAD NV","SellingPrice":230},{"Item Name":"GAMBUS REBOZADAS","SellingPrice":350},{"Item Name":"PANCO FISH FINGER","SellingPrice":270},{"Item Name":"MUSHROOM DUPLEX","SellingPrice":160},{"Item Name":"FRENCH FRIES","SellingPrice":99},{"Item Name":"HONEY GARLIC PRAWN","SellingPrice":350},{"Item Name":"CHICKEN MANCHURIAN","SellingPrice":180},{"Item Name":"MUSHROOM CHILLY","SellingPrice":120},{"Item Name":"SALT N PEPPER BABY CORN","SellingPrice":120},{"Item Name":"SOUTHERN STYLE CHICKEN","SellingPrice":210},{"Item Name":"PANEER NAGGETS","SellingPrice":210},{"Item Name":"HARA BHARA KEBAB","SellingPrice":160},{"Item Name":"CHICKEN TIKKA","SellingPrice":210},{"Item Name":"KALMI KEBAB","SellingPrice":250},{"Item Name":"PIZZA MARGARITTA","SellingPrice":200},{"Item Name":"PIZZA VEG FARMHOUSE","SellingPrice":200},{"Item Name":"BBQ CHICKEN PIZZA","SellingPrice":225},{"Item Name":"CHICKEN TIKKA PIZZA","SellingPrice":225},{"Item Name":"PESTO SAUCE","SellingPrice":175},{"Item Name":"ARABIATA","SellingPrice":160},{"Item Name":"PINK SAUCE","SellingPrice":160},{"Item Name":"GARBANZO BEAN SALAD","SellingPrice":90},{"Item Name":"MASALA PAPAD","SellingPrice":50},{"Item Name":"PEANUT MASALA","SellingPrice":60},{"Item Name":"GAJAR KA HALWA","SellingPrice":90},{"Item Name":"WATERMELON MARTINI","SellingPrice":281.25},{"Item Name":"Kiwi martini","SellingPrice":281.25},{"Item Name":" Apple gin","SellingPrice":225}];

//calculate the number of "pages" with 20 items per page
const rounds = Math.ceil(tableValue.length/20);
//initialize page counter
var round = 1;
//render array of objects into table HTML, based on
//the source data and index (first item on the "page")
const renderTable = (arr, index) => {
  //chop off 20 items starting from "page" counter
  //multiplied by 20
  arr = arr.slice(index*20, index*20+20);
  //break 20 items into array of chunks by 4 items (per row)
  const chunkedArr = arr.reduceRight((res,_,__,self) => [...res, self.splice(0, 4)],[]);
  //map each chunk of 4 items into
 code,
  //reducing each object into pair of  nodes
  //(name, price) and join resulting array of
 codes
  return chunkedArr.map(tr => `<tr>${tr.reduce((rowhtml, td) => rowhtml += `${td['Item Name']}	${td['SellingPrice']}	`, '')}</tr>`).join('');
};
//render initial portion of source data
$('#DisplayTable').html(renderTable(tableValue, 0));
//repeat rendering each 3 seconds, reset counter on the last "page"
const rotateTable = window.setInterval(() => {
   $('#DisplayTable').html(renderTable(tableValue, round));
   if(round == rounds-1) round = 0;
   else round++;
}, 3000);```
<pre class="snippet-code-css lang-css prettyprint-override"><code>td {
  white-space: nowrap;
  border-collapse: collapse;
  font-family: Verdana;
  font-size: 8pt;
  font-weight: bold;
}
td:nth-child(1),td:nth-child(2) {
  background: #4AD184;
}
td:nth-child(3),td:nth-child(4) {
  background: #EA69EF;
}
td:nth-child(5),td:nth-child(6){
  background: #E1A558;
}
td:nth-child(7),td:nth-child(8) {
  background: #F4F065;
}</code>```

<link rel="stylesheet" href="//stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css">

```

Body:
I am working on creating dynamic HTML table from JSON Data, I have already created the table dynamically but now I have to Change it with new Requirement

What I am doing

I have array of objects from which i am creating the table and spiting the table into four columns by dividing the length of JSON to 4

My table is rendering perfectly into 4 columns

What I am trying to Do

I want to show only 5 Rows in a single go then reloads the div and render the next five rows in same dive and so on until all data gets render

Currently I have 68 total data so i am populating it as 17 rows of 4 columns

Now on one go when page lodes I want to show 5 rows then after 5 seconds Next 5 rows in same div

In simple terms I want to split my JSON data into part of 5-5 rows and show only 5 rows at once then next five after 5 seconds

Spiting the Table into Four Columns I have done already,now just want to Show only five rows at a time

I am lacking with idea or approach how to do this, How can i divide my JSON in five-five rows and show them at each time interval of 5 seconds

What I am have done

var tableValue = [{
  "Item Name": "MANCHOW  V SOUP",
  "SellingPrice": 100
}, {
  "Item Name": "MANCHOW NV SOUP ",
  "SellingPrice": 125
}, {
  "Item Name": "CEASER SALAD V",
  "SellingPrice": 175
}, {
  "Item Name": "CEASER SALAD NV",
  "SellingPrice": 230
}, {
  "Item Name": "GAMBUS REBOZADAS",
  "SellingPrice": 350
}, {
  "Item Name": "PANCO FISH FINGER",
  "SellingPrice": 270
}, {
  "Item Name": "MUSHROOM DUPLEX",
  "SellingPrice": 160
}, {
  "Item Name": "FRENCH FRIES",
  "SellingPrice": 99
}, {
  "Item Name": "HONEY GARLIC PRAWN",
  "SellingPrice": 350
}, {
  "Item Name": "CHICKEN MANCHURIAN",
  "SellingPrice": 180
}, {
  "Item Name": "MUSHROOM CHILLY",
  "SellingPrice": 120
}, {
  "Item Name": "SALT N PEPPER BABY CORN",
  "SellingPrice": 120
}, {
  "Item Name": "SOUTHERN STYLE CHICKEN",
  "SellingPrice": 210
}, {
  "Item Name": "PANEER NAGGETS",
  "SellingPrice": 210
}, {
  "Item Name": "HARA BHARA KEBAB",
  "SellingPrice": 160
}, {
  "Item Name": "CHICKEN TIKKA",
  "SellingPrice": 210
}, {
  "Item Name": "KALMI KEBAB",
  "SellingPrice": 250
}, {
  "Item Name": "PIZZA MARGARITTA",
  "SellingPrice": 200
}, {
  "Item Name": "PIZZA VEG FARMHOUSE",
  "SellingPrice": 200
}, {
  "Item Name": "BBQ CHICKEN PIZZA",
  "SellingPrice": 225
}, {
  "Item Name": "CHICKEN TIKKA PIZZA",
  "SellingPrice": 225
}, {
  "Item Name": "PESTO SAUCE",
  "SellingPrice": 175
}, {
  "Item Name": "ARABIATA",
  "SellingPrice": 160
}, {
  "Item Name": "PINK SAUCE",
  "SellingPrice": 160
}, {
  "Item Name": "GARBANZO BEAN SALAD",
  "SellingPrice": 90
}, {
  "Item Name": "MASALA PAPAD",
  "SellingPrice": 50
}, {
  "Item Name": "PEANUT MASALA",
  "SellingPrice": 60
}, {
  "Item Name": "GAJAR KA HALWA",
  "SellingPrice": 90
}, {
  "Item Name": "WATERMELON MARTINI",
  "SellingPrice": 281
}, {
  "Item Name": "Kiwi martini",
  "SellingPrice": 281
}, {
  "Item Name": " Apple gin",
  "SellingPrice": 225
}, {
  "Item Name": "Cucumber  cooler ",
  "SellingPrice": 281
}, {
  "Item Name": "Martini",
  "SellingPrice": 225
}, {
  "Item Name": "Pink lady",
  "SellingPrice": 225
}, {
  "Item Name": " Bloody marry",
  "SellingPrice": 281
}, {
  "Item Name": "Cosmopolitan",
  "SellingPrice": 281
}, {
  "Item Name": "Sex on the beach",
  "SellingPrice": 281
}, {
  "Item Name": "Bull frog",
  "SellingPrice": 506
}, {
  "Item Name": "Long  island iced tea ",
  "SellingPrice": 393
}, {
  "Item Name": "Pinacolada",
  "SellingPrice": 225
}, {
  "Item Name": "Daiquiri",
  "SellingPrice": 225
}, {
  "Item Name": "Mojito ",
  "SellingPrice": 281
}, {
  "Item Name": "Whisky sour",
  "SellingPrice": 281
}, {
  "Item Name": "Hot toddy",
  "SellingPrice": 225
}, {
  "Item Name": "Margarita",
  "SellingPrice": 337
}, {
  "Item Name": "Tequila sunrise",
  "SellingPrice": 337
}, {
  "Item Name": "Red sangria",
  "SellingPrice": 225
}, {
  "Item Name": "White sangria",
  "SellingPrice": 247
}, {
  "Item Name": "Rose sangria",
  "SellingPrice": 247
}, {
  "Item Name": "By chance special ",
  "SellingPrice": 168
}, {
  "Item Name": "Made in heaven",
  "SellingPrice": 168
}, {
  "Item Name": "Strawberry delight",
  "SellingPrice": 168
}, {
  "Item Name": "DRAGON",
  "SellingPrice": 168
}, {
  "Item Name": "Mangochil ",
  "SellingPrice": 168
}, {
  "Item Name": "Cucumber cola",
  "SellingPrice": 168
}, {
  "Item Name": "Virgin mojito",
  "SellingPrice": 168
}, {
  "Item Name": "Virgin mary",
  "SellingPrice": 168
}, {
  "Item Name": "Virgin pinacolada",
  "SellingPrice": 168
}, {
  "Item Name": "CORONA",
  "SellingPrice": 438
}, {
  "Item Name": "CRAFT BEERS",
  "SellingPrice": 337
}, {
  "Item Name": "BIRA WHITE 330",
  "SellingPrice": 157
}, {
  "Item Name": "BIRA BLONDE 330",
  "SellingPrice": 135
}, {
  "Item Name": "BIRA STRONG 650",
  "SellingPrice": 213
}, {
  "Item Name": "KINGFISHER PREMIUM 330",
  "SellingPrice": 123
}, {
  "Item Name": "KINGFISHER PREMIUM 650",
  "SellingPrice": 202
}, {
  "Item Name": "KINGFISHER STRONG 330",
  "SellingPrice": 135
}, {
  "Item Name": "KINGFISHER STRONG 650",
  "SellingPrice": 213
}, {
  "Item Name": "KINGFISHER ULTRA 330",
  "SellingPrice": 146
}, {
  "Item Name": "KINGFISHER ULTRA 650",
  "SellingPrice": 281
}, {
  "Item Name": "KINGFISHER ULTRA MAX 330",
  "SellingPrice": 146
}, {
  "Item Name": "KINGFISHER ULTRA MAX 650",
  "SellingPrice": 281
}, {
  "Item Name": "BUDWIESER 330",
  "SellingPrice": 146
}, {
  "Item Name": "BUDWIESER 650",
  "SellingPrice": 270
}, {
  "Item Name": "BUDWIESER MAGNUM 330",
  "SellingPrice": 168
}, {
  "Item Name": "BUDWIESER MAGNUM 650",
  "SellingPrice": 281
}, {
  "Item Name": "TUBORG 330",
  "SellingPrice": 123
}, {
  "Item Name": "TUBORG 650",
  "SellingPrice": 191
}, {
  "Item Name": "TUBORG STRONG 330",
  "SellingPrice": 123
}, {
  "Item Name": "TUBORG STRONG 650",
  "SellingPrice": 213
}, {
  "Item Name": "CRANBERRY ",
  "SellingPrice": 157
}, {
  "Item Name": "ORANGE",
  "SellingPrice": 157
}, {
  "Item Name": "JAMICAN",
  "SellingPrice": 157
}, {
  "Item Name": "BLACK BERRY",
  "SellingPrice": 157
}, {
  "Item Name": "BLUE BERRY",
  "SellingPrice": 157
}, {
  "Item Name": "MOET CHANDON",
  "SellingPrice": 7875
}, {
  "Item Name": "SULA BRUT",
  "SellingPrice": 1687
}, {
  "Item Name": "MATEUS ROSE",
  "SellingPrice": 2137
}, {
  "Item Name": "HARDYS SIRAZ CABERNET 750",
  "SellingPrice": 1890
}, {
  "Item Name": "HARDYS SIRAZ CABERNET BY GLASS",
  "SellingPrice": 382
}, {
  "Item Name": "JACOB CREEK SIRAZ 750",
  "SellingPrice": 1800
}, {
  "Item Name": "JACOB CREEK SIRAZ BY GLASS",
  "SellingPrice": 360
}, {
  "Item Name": "BIG BANAYAN CHENNIN BLANC 750",
  "SellingPrice": 990
}, {
  "Item Name": "BIG BANAYAN CHENNIN BLANC BY GLASS",
  "SellingPrice": 202
}, {
  "Item Name": "SULA CHENIN BLANC 750 ",
  "SellingPrice": 1293
}, {
  "Item Name": "SULA CHENIN BLANC BY GLASS",
  "SellingPrice": 258
}, {
  "Item Name": "FOUR SEAZON CLASSIC CHENNIN BLANC 750",
  "SellingPrice": 1125
}, {
  "Item Name": "FOUR SEAZON CLASSIC CHENNIN BLANC BY GLASS",
  "SellingPrice": 225
}, {
  "Item Name": "BIG BANAYAN CARBINET SAUVIGNON 750",
  "SellingPrice": 1125
}, {
  "Item Name": "BIG BANAYAN CARBINET SAUVIGNON BY GLASS",
  "SellingPrice": 225
}, {
  "Item Name": "SULA SATORI MERLOT 750",
  "SellingPrice": 1237
}, {
  "Item Name": "SULA SATORI MERLOT BY GLASS",
  "SellingPrice": 247
}, {
  "Item Name": "GROVERS LA RESERVE 750",
  "SellingPrice": 1800
}, {
  "Item Name": "GROVERS LA RESERVE 100",
  "SellingPrice": 360
}, {
  "Item Name": "GLENFIDDICH 12 YEARS 700 ",
  "SellingPrice": 9225
}, {
  "Item Name": "GLENFIDDICH 12 YEARS 30",
  "SellingPrice": 405
}, {
  "Item Name": "TALISKER 750",
  "SellingPrice": 8775
}, {
  "Item Name": "TALISKER 30",
  "SellingPrice": 360
}, {
  "Item Name": "GLENNLIVET 750",
  "SellingPrice": 8887
}, {
  "Item Name": "GLENNLIVET 30",
  "SellingPrice": 360
}, {
  "Item Name": "THE SINGLETON 750",
  "SellingPrice": 7942
}, {
  "Item Name": "THE SINGLETON 30",
  "SellingPrice": 326
}, {
  "Item Name": "AMRUT FUSION 750",
  "SellingPrice": 5062
}, {
  "Item Name": "AMRUT FUSION 30",
  "SellingPrice": 202
}, {
  "Item Name": "JACK DANIELS 750",
  "SellingPrice": 7312
}, {
  "Item Name": "JACK DANIELS 30",
  "SellingPrice": 292
}, {
  "Item Name": "JIM BEAM WHITE 750",
  "SellingPrice": 4095
}, {
  "Item Name": "JIM BEAM WHITE 30",
  "SellingPrice": 168
}, {
  "Item Name": "JAMESON 750",
  "SellingPrice": 4950
}, {
  "Item Name": "JAMESON 30",
  "SellingPrice": 202
}, {
  "Item Name": "JW BLACK LABEL 750",
  "SellingPrice": 8212
}, {
  "Item Name": "JW BLACK LABEL 200",
  "SellingPrice": 2925
}, {
  "Item Name": "JW BLACK LABEL 30",
  "SellingPrice": 337
}, {
  "Item Name": "JW RED LABEL 200",
  "SellingPrice": 1158
}, {
  "Item Name": "BALLENTINSE FINEST BLENDED 750",
  "SellingPrice": 4545
}, {
  "Item Name": "BALLENTINSE FINEST BLENDED 30",
  "SellingPrice": 180
}, {
  "Item Name": "BLACK \u0026 WHITE 375",
  "SellingPrice": 1575
}, {
  "Item Name": "BLACK \u0026 WHITE 180",
  "SellingPrice": 787
}, {
  "Item Name": "BLACK \u0026 WHITE 60",
  "SellingPrice": 258
}, {
  "Item Name": "BLACK \u0026 WHITE 30",
  "SellingPrice": 135
}, {
  "Item Name": "100 PIPERS 180",
  "SellingPrice": 787
}, {
  "Item Name": "100 PIPERS 60",
  "SellingPrice": 258
}, {
  "Item Name": "100 PIPERS 30",
  "SellingPrice": 135
}, {
  "Item Name": "VAT 69 180",
  "SellingPrice": 675
}, {
  "Item Name": "VAT 69 60",
  "SellingPrice": 225
}, {
  "Item Name": "VAT 69 30",
  "SellingPrice": 112
}, {
  "Item Name": "TEACHERS HIGHLAND 180",
  "SellingPrice": 787
}, {
  "Item Name": "TEACHERS HIGHLAND 60",
  "SellingPrice": 258
}, {
  "Item Name": "TEACHERS HIGHLAND 30",
  "SellingPrice": 135
}, {
  "Item Name": "TEACHERS 50 60",
  "SellingPrice": 393
}, {
  "Item Name": "TEACHERS 50 30",
  "SellingPrice": 202
}, {
  "Item Name": "BLACK DOG TRIPPLE GOLD 180",
  "SellingPrice": 1215
}, {
  "Item Name": "BLACK DOG TRIPPLE GOLD 30",
  "SellingPrice": 213
}, {
  "Item Name": "BLACK DOG 8 YEARS 180",
  "SellingPrice": 731
}, {
  "Item Name": "BLACK DOG 8 YEARS 60",
  "SellingPrice": 247
}, {
  "Item Name": "BLACK DOG 8 YEARS 30",
  "SellingPrice": 123
}, {
  "Item Name": "BLENDERS PRIDE 750",
  "SellingPrice": 2283
}, {
  "Item Name": "BLENDERS PRIDE 375",
  "SellingPrice": 1147
}, {
  "Item Name": "BLENDERS PRIDE 180",
  "SellingPrice": 573
}, {
  "Item Name": "BLENDERS PRIDE 60",
  "SellingPrice": 191
}, {
  "Item Name": "BLENDERS PRIDE 30",
  "SellingPrice": 90
}, {
  "Item Name": "SIGNATURE 180",
  "SellingPrice": 450
}, {
  "Item Name": "SIGNATURE 60",
  "SellingPrice": 168
}, {
  "Item Name": "SIGNATURE 30",
  "SellingPrice": 90
}, {
  "Item Name": "GREY GOOSE 750",
  "SellingPrice": 8190
}, {
  "Item Name": "GREY GOOSE 30",
  "SellingPrice": 326
}, {
  "Item Name": "BELVEDERE 700",
  "SellingPrice": 8122
}, {
  "Item Name": "BELVEDERE 30",
  "SellingPrice": 360
}, {
  "Item Name": "CIROC 750",
  "SellingPrice": 7425
}, {
  "Item Name": "CIROC 30",
  "SellingPrice": 303
}, {
  "Item Name": "ABSOLUT 750",
  "SellingPrice": 4556
}, {
  "Item Name": "ABSOLUT 30",
  "SellingPrice": 191
}, {
  "Item Name": "SMIRNOFF RED 180",
  "SellingPrice": 551
}, {
  "Item Name": "SMIRNOFF RED 60",
  "SellingPrice": 202
}, {
  "Item Name": "SMIRNOFF RED30",
  "SellingPrice": 101
}, {
  "Item Name": "SMIRNOFF ORANGE 180",
  "SellingPrice": 551
}, {
  "Item Name": "SMIRNOFF ORANGE 60",
  "SellingPrice": 202
}, {
  "Item Name": "SMINOFF ORANGE30",
  "SellingPrice": 101
}, {
  "Item Name": "SMIRNOFF GREEN APPLE 180",
  "SellingPrice": 551
}, {
  "Item Name": "SMIRNOFF GREEN APPLE 60",
  "SellingPrice": 202
}, {
  "Item Name": "SMIRNOFF GREEN APPLE30",
  "SellingPrice": 101
}, {
  "Item Name": "BOMBAY SAPHIRE 750",
  "SellingPrice": 4725
}, {
  "Item Name": "BOMBAY SAPHIRE 30",
  "SellingPrice": 191
}, {
  "Item Name": "BLUE RIBBAND 750",
  "SellingPrice": 877
}, {
  "Item Name": "BLUE RIBBAND 60",
  "SellingPrice": 78
}, {
  "Item Name": "BACCARDI WHITE 750",
  "SellingPrice": 2418
}, {
  "Item Name": "BACCARDI WHITE 180",
  "SellingPrice": 585
}, {
  "Item Name": "BACCARDI WHITE 60",
  "SellingPrice": 202
}, {
  "Item Name": "BACCARDI WHITE 30",
  "SellingPrice": 101
}, {
  "Item Name": "BACCARDI LEMON 180",
  "SellingPrice": 585
}, {
  "Item Name": "BACCARDI LEMON 60",
  "SellingPrice": 202
}, {
  "Item Name": "BACCARDI LEMON 30",
  "SellingPrice": 101
}, {
  "Item Name": "BACCARDI ORANGE 180",
  "SellingPrice": 585
}, {
  "Item Name": "BACCARDI ORANGE 60",
  "SellingPrice": 202
}, {
  "Item Name": "BACCARDI LEMON 30",
  "SellingPrice": 101
}, {
  "Item Name": "BACCARDI BLACK 180",
  "SellingPrice": 393
}, {
  "Item Name": "BACCARDI BLACK 30",
  "SellingPrice": 67
}, {
  "Item Name": "BACCARDI GOLD 180",
  "SellingPrice": 585
}, {
  "Item Name": "BACCARDI GOLD30",
  "SellingPrice": 101
}, {
  "Item Name": "OLD MONK 180",
  "SellingPrice": 225
}, {
  "Item Name": "OLD MONK 90",
  "SellingPrice": 168
}, {
  "Item Name": "OLD MONK 60",
  "SellingPrice": 90
}, {
  "Item Name": "OLD MONK 30 ",
  "SellingPrice": 45
}, {
  "Item Name": "DON ANGEL 750",
  "SellingPrice": 4668
}, {
  "Item Name": "DON ANGEL 30",
  "SellingPrice": 191
}, {
  "Item Name": "SAUZA SILVER 700",
  "SellingPrice": 6153
}, {
  "Item Name": "SAUZA SILVER 30",
  "SellingPrice": 270
}, {
  "Item Name": "JAGERBOMB",
  "SellingPrice": 506
}, {
  "Item Name": "KAMAKAZI",
  "SellingPrice": 168
}, {
  "Item Name": "JAGERMASTER",
  "SellingPrice": 303
}, {
  "Item Name": "COINTTRAEU",
  "SellingPrice": 303
}, {
  "Item Name": "SAMBUCA",
  "SellingPrice": 258
}, {
  "Item Name": "KHALUA",
  "SellingPrice": 168
}, {
  "Item Name": "MARTINI BLANCO",
  "SellingPrice": 90
}, {
  "Item Name": "MARTINI ROSSO",
  "SellingPrice": 90
}, {
  "Item Name": "HENESSY VS 700",
  "SellingPrice": 7875
}, {
  "Item Name": "HENESSY VS 30",
  "SellingPrice": 348
}, {
  "Item Name": "MORPHEUS 750",
  "SellingPrice": 2182
}, {
  "Item Name": "MORPHEUS 180",
  "SellingPrice": 540
}, {
  "Item Name": "MORPHEUS 60",
  "SellingPrice": 191
}, {
  "Item Name": "MORPHEUS 30",
  "SellingPrice": 101
}, {
  "Item Name": "MANSION HOUSE 180",
  "SellingPrice": 292
}, {
  "Item Name": "MANSION HOUSE 90",
  "SellingPrice": 168
}, {
  "Item Name": "MANSION HOUSE 60",
  "SellingPrice": 90
}, {
  "Item Name": "MC BRANDY 60",
  "SellingPrice": 90
}, {
  "Item Name": "RED BULL ",
  "SellingPrice": 157
}, {
  "Item Name": "COKE",
  "SellingPrice": 45
}, {
  "Item Name": "SPRITE",
  "SellingPrice": 45
}, {
  "Item Name": "SODA",
  "SellingPrice": 33
}, {
  "Item Name": "DIET COKE",
  "SellingPrice": 56
}, {
  "Item Name": "TONIC WATER",
  "SellingPrice": 67
}, {
  "Item Name": "GINGER ALE",
  "SellingPrice": 67
}, {
  "Item Name": "LIME SODA",
  "SellingPrice": 45
}, {
  "Item Name": "LIME WATER",
  "SellingPrice": 45
}, {
  "Item Name": "PACKEGED WATER 1L",
  "SellingPrice": 39
}, {
  "Item Name": "MANSION HOUSE 650",
  "SellingPrice": 900
}, {
  "Item Name": "Chole Kulche",
  "SellingPrice": 80
}, {
  "Item Name": "Butter Nan",
  "SellingPrice": 65
}, {
  "Item Name": "Dhai",
  "SellingPrice": 20
}, {
  "Item Name": "Rice",
  "SellingPrice": 55
}, {
  "Item Name": "Plain rice",
  "SellingPrice": 30
}, {
  "Item Name": "MANSION HOUSE 650",
  "SellingPrice": 900
}, {
  "Item Name": "Chole Kulche",
  "SellingPrice": 80
}, {
  "Item Name": "Butter Nan",
  "SellingPrice": 65
}, {
  "Item Name": "Dhai",
  "SellingPrice": 20
}, {
  "Item Name": "Rice",
  "SellingPrice": 55
}, {
  "Item Name": "Plain rice",
  "SellingPrice": 30
}]

myFun();
window.setInterval(showRows, 5000);
showRows();

function myFun() {
  addTable(tableValue);
}

function showRows() {
  $(".hidden:lt(10)").removeClass("hidden");
}

function addTable(tableValue) {
  var $tbl = $("
", {
      "class": "table"
    }),

    $tb = $("
"),
    $trh = $("
");

  var split = Math.round(tableValue.length / 4);
  for (i = 0; i < split; i++) {
    $tr = $("
", {
      class: "hidden"
    });
    for (j = 0; j < 4; j++) {
      $.each(tableValue[split * j + i], function(key, value) {

        $("", {
          "class": "text-left color" + (j + 1)
        }).html(value).appendTo($tr);
      });
    }
    $tr.appendTo($tb);
  }
  $tbl.append($tb);
  $("#DisplayTable").html($tbl);
}

tbody>tr>td {
  white-space: nowrap;
  border-collapse: collapse;
  font-family: Verdana;
  font-size: 8pt;
  font-weight: bold;
  white-space: nowrap;
}

.color1 {
  background: #4AD184;
}

.color2 {
  background: #EA69EF;
}

.color3 {
  background: #E1A558;
}

.color4 {
  background: #F4F065;
}

<link rel="stylesheet" href="//stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css">

Edit
I have tried @Void's solution but that is not removing the hidden class,when I inspect the element then there is no class applied to tr it is showing as class=""

Body:
You may use Array.prototype.slice() to extract portion of the array and render that into html:

//source data sample
const tableValue=[{"Item Name":"MANCHOW  V SOUP","SellingPrice":100},{"Item Name":"MANCHOW NV SOUP ","SellingPrice":125},{"Item Name":"CEASER SALAD V","SellingPrice":175},{"Item Name":"CEASER SALAD NV","SellingPrice":230},{"Item Name":"GAMBUS REBOZADAS","SellingPrice":350},{"Item Name":"PANCO FISH FINGER","SellingPrice":270},{"Item Name":"MUSHROOM DUPLEX","SellingPrice":160},{"Item Name":"FRENCH FRIES","SellingPrice":99},{"Item Name":"HONEY GARLIC PRAWN","SellingPrice":350},{"Item Name":"CHICKEN MANCHURIAN","SellingPrice":180},{"Item Name":"MUSHROOM CHILLY","SellingPrice":120},{"Item Name":"SALT N PEPPER BABY CORN","SellingPrice":120},{"Item Name":"SOUTHERN STYLE CHICKEN","SellingPrice":210},{"Item Name":"PANEER NAGGETS","SellingPrice":210},{"Item Name":"HARA BHARA KEBAB","SellingPrice":160},{"Item Name":"CHICKEN TIKKA","SellingPrice":210},{"Item Name":"KALMI KEBAB","SellingPrice":250},{"Item Name":"PIZZA MARGARITTA","SellingPrice":200},{"Item Name":"PIZZA VEG FARMHOUSE","SellingPrice":200},{"Item Name":"BBQ CHICKEN PIZZA","SellingPrice":225},{"Item Name":"CHICKEN TIKKA PIZZA","SellingPrice":225},{"Item Name":"PESTO SAUCE","SellingPrice":175},{"Item Name":"ARABIATA","SellingPrice":160},{"Item Name":"PINK SAUCE","SellingPrice":160},{"Item Name":"GARBANZO BEAN SALAD","SellingPrice":90},{"Item Name":"MASALA PAPAD","SellingPrice":50},{"Item Name":"PEANUT MASALA","SellingPrice":60},{"Item Name":"GAJAR KA HALWA","SellingPrice":90},{"Item Name":"WATERMELON MARTINI","SellingPrice":281.25},{"Item Name":"Kiwi martini","SellingPrice":281.25},{"Item Name":" Apple gin","SellingPrice":225}];

//calculate the number of "pages" with 20 items per page
const rounds = Math.ceil(tableValue.length/20);
//initialize page counter
var round = 1;
//render array of objects into table HTML, based on
//the source data and index (first item on the "page")
const renderTable = (arr, index) => {
  //chop off 20 items starting from "page" counter
  //multiplied by 20
  arr = arr.slice(index*20, index*20+20);
  //break 20 items into array of chunks by 4 items (per row)
  const chunkedArr = arr.reduceRight((res,_,__,self) => [...res, self.splice(0, 4)],[]);
  //map each chunk of 4 items into <tr> code,
  //reducing each object into pair of <td> nodes
  //(name, price) and join resulting array of <tr> codes
  return chunkedArr.map(tr => `<tr>${tr.reduce((rowhtml, td) => rowhtml += `<td class="text-left">${td['Item Name']}</td><td class="text-right">${td['SellingPrice']}</td>`, '')}</tr>`).join('');
};
//render initial portion of source data
$('#DisplayTable').html(renderTable(tableValue, 0));
//repeat rendering each 3 seconds, reset counter on the last "page"
const rotateTable = window.setInterval(() => {
   $('#DisplayTable').html(renderTable(tableValue, round));
   if(round == rounds-1) round = 0;
   else round++;
}, 3000);

td {
  white-space: nowrap;
  border-collapse: collapse;
  font-family: Verdana;
  font-size: 8pt;
  font-weight: bold;
}
td:nth-child(1),td:nth-child(2) {
  background: #4AD184;
}
td:nth-child(3),td:nth-child(4) {
  background: #EA69EF;
}
td:nth-child(5),td:nth-child(6){
  background: #E1A558;
}
td:nth-child(7),td:nth-child(8) {
  background: #F4F065;
}

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="//stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css">
<table class="table" id="DisplayTable">
</table>


问:
How to include bootstrap css and js in reactjs app?
I am new to ReactJS, I want to include bootstrap in my React app

I have installed bootstrap by npm install bootstrap --save

Now, want to load bootstrap CSS and JS in my React app.

I am using webpack.

webpack.config.js

```<code>var config = {
    entry: './src/index',

    output: {
        path: './',
        filename: 'index.js'
    },

    devServer: {
        inline: true,
        port: 8080,
        historyApiFallback: true,
        contentBase:'./src'
    },

    module: {
        loaders: [
            {
                test: /\.js?$/,
                exclude: /node_modules/,
                loader: 'babel',

                query: {
                    presets: ['es2015', 'react']
               }
            }
        ]
    }
};

module. exports = config;
</code>```

My issue is “how to include bootstrap CSS and JS in ReactJS app from node modules?" How to set up for bootstrap to include in my React app?

答:
I try with instruction:

```<code>npm install bootstrap
npm install jquery popper.js
</code>```

then in src/index.js:

```<code>import 'bootstrap/dist/css/bootstrap.min.css';
import $ from 'jquery';
import Popper from 'popper.js';
import 'bootstrap/dist/js/bootstrap.bundle.min';
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import registerServiceWorker from './registerServiceWorker';

ReactDOM.render(<Dropdown />, document.getElementById('root'));
registerServiceWorker();
</code>```

Body:
I am new to ReactJS, I want to include bootstrap in my React app

I have installed bootstrap by npm install bootstrap --save

Now, want to load bootstrap CSS and JS in my React app.

I am using webpack.

webpack.config.js

var config = {
    entry: './src/index',

    output: {
        path: './',
        filename: 'index.js'
    },

    devServer: {
        inline: true,
        port: 8080,
        historyApiFallback: true,
        contentBase:'./src'
    },

    module: {
        loaders: [
            {
                test: /\.js?$/,
                exclude: /node_modules/,
                loader: 'babel',

                query: {
                    presets: ['es2015', 'react']
               }
            }
        ]
    }
};

module. exports = config;

My issue is “how to include bootstrap CSS and JS in ReactJS app from node modules?" How to set up for bootstrap to include in my React app?

Body:
I try with instruction:

npm install bootstrap
npm install jquery popper.js

then in src/index.js:

import 'bootstrap/dist/css/bootstrap.min.css';
import $ from 'jquery';
import Popper from 'popper.js';
import 'bootstrap/dist/js/bootstrap.bundle.min';
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import registerServiceWorker from './registerServiceWorker';

ReactDOM.render(<Dropdown />, document.getElementById('root'));
registerServiceWorker();


问:
How to extract the population figure of a country from en.wikipedia.org using Selenium through Java
I am trying to extract the population figure/text of an element.

I tried with parent but its showing error. I am trying to get the Population of China from this page table https://en.wikipedia.org/wiki/China

Code trial:

```<code>WebElement dateBox7 = driver.findElement(By.xpath("//*[contains(text(),'Population')]/parent::tr//td/a[text()]"));
</code>```

Error:

```<code>Exception in thread "main" org.openqa.selenium.NoSuchElementException:
</code>```

I have tried //*[contains(text(),'2016 estimate')]/ancestor::tr/td/text()[1] this xpath it's showing the population in DOM.But in selenium it's showing error:

```<code>Exception in thread "main" org.openqa.selenium.InvalidSelectorException: invalid selector: The result of the xpath expression "//*[contains(text(),'2016 estimate')]/ancestor::tr/td/text()[1]" is: [object Text]. It should be an element.
</code>```

Why it's not working?

答:
Try with this xpath

```<code>"//*[contains(.,'Population')]/parent::tr//th/a[text()]"
</code>```

Note there are two changes: td -> th, and [contains(text(),'Population')] -> [contains(.,'Population')].

When searching for [contains(.,'Population')] the "dot" means searching all text inside of the element (including the descendants) while "text()" will search only for the direct textural content of the element.

EDIT:

Based on your comment, try this xpath:

```<code>"//*[contains(.,'Population')]/parent::tr/following-sibling::tr[1]/td"
</code>```

EDIT #2:

For a tutorial on Xpath locators, see here and for a free course on the topic see here.

Body:
I am trying to extract the population figure/text of an element.

I tried with parent but its showing error. I am trying to get the Population of China from this page table https://en.wikipedia.org/wiki/China

Code trial:

WebElement dateBox7 = driver.findElement(By.xpath("//*[contains(text(),'Population')]/parent::tr//td/a[text()]"));

Error:

Exception in thread "main" org.openqa.selenium.NoSuchElementException:

I have tried //*[contains(text(),'2016 estimate')]/ancestor::tr/td/text()[1] this xpath it's showing the population in DOM.But in selenium it's showing error:

Exception in thread "main" org.openqa.selenium.InvalidSelectorException: invalid selector: The result of the xpath expression "//*[contains(text(),'2016 estimate')]/ancestor::tr/td/text()[1]" is: [object Text]. It should be an element.

Why it's not working?

Body:
Try with this xpath

"//*[contains(.,'Population')]/parent::tr//th/a[text()]"

Note there are two changes: td -> th, and [contains(text(),'Population')] -> [contains(.,'Population')].

When searching for [contains(.,'Population')] the "dot" means searching all text inside of the element (including the descendants) while "text()" will search only for the direct textural content of the element.

EDIT:

Based on your comment, try this xpath:

"//*[contains(.,'Population')]/parent::tr/following-sibling::tr[1]/td"

EDIT #2:

For a tutorial on Xpath locators, see here and for a free course on the topic see here.


问:
Nodejs formidable library loop through files
everyone I want to loop the files array given by formidable library on Nodejs, here is the post function:

```<code>form.parse(req, (err, fields, files) => {
        console.log(files);
        let filesPaths = [];

        files.forEach(file => {
            filesPaths.push(file.path)
        });

        res.json({
            filesPaths
        })
})
</code>```

and I was just following this Youtube Tutorial, and strangely it did not work as it did in the video, I get Cannot read property 'forEach' of undefined error, even though I do get results from the console.log(files)

Here is the log from console.log(files):

```<code> { test:
   File {
     _events: [Object: null prototype] {},
     _eventsCount: 0,
     _maxListeners: undefined,
     size: 57417,
     path: 'uploads\\upload_ecc62d10fe1c5f0c60786125211a95eb.jpg',
     name: 'products_364475.jpg',
     type: 'image/jpeg',
     hash: null,
     lastModifiedDate: 2019-05-28T00:03:31.636Z,
     _writeStream:
      WriteStream {
        _writableState: [WritableState],
        writable: false,
        _events: [Object: null prototype] {},
        _eventsCount: 0,
        _maxListeners: undefined,
        path: 'uploads\\upload_ecc62d10fe1c5f0c60786125211a95eb.jpg',
        fd: null,
        flags: 'w',
        mode: 438,
        start: undefined,
        autoClose: true,
        pos: undefined,
        bytesWritten: 57417,
        closed: false } },
  test2:
   File {
     _events: [Object: null prototype] {},
     _eventsCount: 0,
     _maxListeners: undefined,
     size: 11296,
     path: 'uploads\\upload_15de2858098a654c11ac08400b0c18d8.jpg',
     name: 'download.jpg',
     type: 'image/jpeg',
     hash: null,
     lastModifiedDate: 2019-05-28T00:03:31.637Z,
     _writeStream:
      WriteStream {
        _writableState: [WritableState],
        writable: false,
        _events: [Object: null prototype] {},
        _eventsCount: 0,
        _maxListeners: undefined,
        path: 'uploads\\upload_15de2858098a654c11ac08400b0c18d8.jpg',
        fd: null,
        flags: 'w',
        mode: 438,
        start: undefined,
        autoClose: true,
        pos: undefined,
        bytesWritten: 11296,
        closed: false } } }
</code>```

答:
Here is how I parsed and looped through files:

```<code>let filesArray = [];

    let json = JSON.parse(JSON.stringify(files));

    let key = Object.keys(json);

    json[key].forEach(j => {
       filesArray.push(j.path.split("\\")[1]);
    });

    res.json({
        filesArray
    })
</code>```

Body:
everyone I want to loop the files array given by formidable library on Nodejs, here is the post function:

form.parse(req, (err, fields, files) => {
        console.log(files);
        let filesPaths = [];

        files.forEach(file => {
            filesPaths.push(file.path)
        });

        res.json({
            filesPaths
        })
})

and I was just following this Youtube Tutorial, and strangely it did not work as it did in the video, I get Cannot read property 'forEach' of undefined error, even though I do get results from the console.log(files)

Here is the log from console.log(files):

 { test:
   File {
     _events: [Object: null prototype] {},
     _eventsCount: 0,
     _maxListeners: undefined,
     size: 57417,
     path: 'uploads\\upload_ecc62d10fe1c5f0c60786125211a95eb.jpg',
     name: 'products_364475.jpg',
     type: 'image/jpeg',
     hash: null,
     lastModifiedDate: 2019-05-28T00:03:31.636Z,
     _writeStream:
      WriteStream {
        _writableState: [WritableState],
        writable: false,
        _events: [Object: null prototype] {},
        _eventsCount: 0,
        _maxListeners: undefined,
        path: 'uploads\\upload_ecc62d10fe1c5f0c60786125211a95eb.jpg',
        fd: null,
        flags: 'w',
        mode: 438,
        start: undefined,
        autoClose: true,
        pos: undefined,
        bytesWritten: 57417,
        closed: false } },
  test2:
   File {
     _events: [Object: null prototype] {},
     _eventsCount: 0,
     _maxListeners: undefined,
     size: 11296,
     path: 'uploads\\upload_15de2858098a654c11ac08400b0c18d8.jpg',
     name: 'download.jpg',
     type: 'image/jpeg',
     hash: null,
     lastModifiedDate: 2019-05-28T00:03:31.637Z,
     _writeStream:
      WriteStream {
        _writableState: [WritableState],
        writable: false,
        _events: [Object: null prototype] {},
        _eventsCount: 0,
        _maxListeners: undefined,
        path: 'uploads\\upload_15de2858098a654c11ac08400b0c18d8.jpg',
        fd: null,
        flags: 'w',
        mode: 438,
        start: undefined,
        autoClose: true,
        pos: undefined,
        bytesWritten: 11296,
        closed: false } } }

Body:
Here is how I parsed and looped through files:

let filesArray = [];

    let json = JSON.parse(JSON.stringify(files));

    let key = Object.keys(json);

    json[key].forEach(j => {
       filesArray.push(j.path.split("\\")[1]);
    });

    res.json({
        filesArray
    })


问:
Return type is () -> MultipartBody.Part! instead of MultipartBody.Part
I am relatively new to lambda expressions and would love it if somebody could explain why the return type is different from I am expecting. What is () -> MultipartBody.Part! anyways?

```<code>Single.just{
    val file = bitmapToFile(context, fileName, image)
    // create RequestBody instance from file
    val requestFile = RequestBody.create(
        MediaType.parse("multipart/form-data")
        , file
    )

    // MultipartBody.Part is used to send also the actual file name
    return@just MultipartBody.Part.createFormData("picture", file.name, requestFile)
}
</code>```

答:
In addition to what @reckter said, which is correct, the return type is a lambda instead of a MultipartBody.Part object because of the way you're calling Single.just.

More in detail, Single.just takes 1 argument of type T and returns a Single<T>, as described in the javadoc. In your code you're passing a lambda (i.e., something in the form of { ... }) as argument, hence you'll get back a Single<lambda>. Note that you can omit the parentheses around the lambda because of Kotlin syntax. To solve the issue you can slightly change your code:

```<code>val file = bitmapToFile(context, fileName, image)
// create RequestBody instance from file
val requestFile = RequestBody.create(
    MediaType.parse("multipart/form-data")
    , file
)

val mySingle = Single.just(MultipartBody.Part.createFormData("picture", file.name, requestFile))
</code>```

Body:
I am relatively new to lambda expressions and would love it if somebody could explain why the return type is different from I am expecting. What is () -> MultipartBody.Part! anyways?

Single.just{
    val file = bitmapToFile(context, fileName, image)
    // create RequestBody instance from file
    val requestFile = RequestBody.create(
        MediaType.parse("multipart/form-data")
        , file
    )

    // MultipartBody.Part is used to send also the actual file name
    return@just MultipartBody.Part.createFormData("picture", file.name, requestFile)
}

Body:
In addition to what @reckter said, which is correct, the return type is a lambda instead of a MultipartBody.Part object because of the way you're calling Single.just.

More in detail, Single.just takes 1 argument of type T and returns a Single<T>, as described in the javadoc. In your code you're passing a lambda (i.e., something in the form of { ... }) as argument, hence you'll get back a Single<lambda>. Note that you can omit the parentheses around the lambda because of Kotlin syntax. To solve the issue you can slightly change your code:

val file = bitmapToFile(context, fileName, image)
// create RequestBody instance from file
val requestFile = RequestBody.create(
    MediaType.parse("multipart/form-data")
    , file
)

val mySingle = Single.just(MultipartBody.Part.createFormData("picture", file.name, requestFile))