问:
Build Windows RCP Application on Unix Machine
We're trying to do an Eclipse PDE build for a RCP Application via Hudson/Jenkins. We were doing this so far successfully on a Windows machine (Hudson running on Windows Server 2003). We have decided to move our CI system to a unix machine.
When executing the same build on the unix machine our build fails with the following error:

```
!SESSION 2011-04-12 01:00:49.497 -----------------------------------------------
eclipse.buildId=unknown
java.version=1.6.0_23
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=win32, ARCH=sparc, WS=win32, NL=en_US
Framework arguments:  -application org.eclipse.ant.core.antRunner -buildfile /appl/midw/jenkins/jobs/AP_NAPF/workspace/TP/plugins/org.eclipse.pde.build_3.4.1.R34x_v20081217/scripts/build.xml main -Ddummy=true
Command-line arguments:  -ws win32 -os win32 -application org.eclipse.ant.core.antRunner -buildfile /appl/midw/jenkins/jobs/AP_NAPF/workspace/TP/plugins/org.eclipse.pde.build_3.4.1.R34x_v20081217/scripts/build.xml main -data /appl/midw/jenkins/jobs/AP_NAPF/workspace/ap_build/workspace -Ddummy=true

!ENTRY org.eclipse.osgi 4 0 2011-04-12 01:00:58.961
!MESSAGE An error occurred while automatically activating bundle org.eclipse.ui.workbench (687).
!STACK 0
org.osgi.framework.BundleException: The activator org.eclipse.ui.internal.WorkbenchPlugin for bundle org.eclipse.ui.workbench is invalid
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadBundleActivator(AbstractBundle.java:146)
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:980)
    at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:346)
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:265)
    at org.eclipse.osgi.framework.util.SecureAction.start(SecureAction.java:400)
    at org.eclipse.core.runtime.internal.adaptor.EclipseLazyStarter.postFindLocalClass(EclipseLazyStarter.java:111)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass(ClasspathManager.java:427)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.findLocalClass(DefaultClassLoader.java:193)
    at org.eclipse.osgi.framework.internal.core.BundleLoader.findLocalClass(BundleLoader.java:370)
    at org.eclipse.osgi.framework.internal.core.SingleSourcePackage.loadClass(SingleSourcePackage.java:33)
    at org.eclipse.osgi.framework.internal.core.BundleLoader.findClassInternal(BundleLoader.java:443)
    at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:399)
    at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:387)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:87)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.defineClass(DefaultClassLoader.java:165)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.defineClass(ClasspathManager.java:554)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findClassImpl(ClasspathManager.java:524)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClassImpl(ClasspathManager.java:455)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass_LockClassLoader(ClasspathManager.java:443)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass(ClasspathManager.java:423)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.findLocalClass(DefaultClassLoader.java:193)
    at org.eclipse.osgi.framework.internal.core.BundleLoader.findLocalClass(BundleLoader.java:370)
    at org.eclipse.osgi.framework.internal.core.BundleLoader.findClassInternal(BundleLoader.java:446)
    at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:399)
    at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:387)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:87)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    at org.eclipse.osgi.framework.internal.core.BundleLoader.loadClass(BundleLoader.java:315)
    at org.eclipse.osgi.framework.internal.core.BundleHost.loadClass(BundleHost.java:227)
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadBundleActivator(AbstractBundle.java:139)
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:980)
    at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:346)
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:265)
    at org.eclipse.osgi.framework.util.SecureAction.start(SecureAction.java:400)
    at org.eclipse.osgi.framework.internal.core.BundleHost.loadClass(BundleHost.java:234)
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadClass(AbstractBundle.java:1274)
    at org.eclipse.ant.core.AntCorePreferences$WrappedClassLoader.findClass(AntCorePreferences.java:115)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    at org.eclipse.ant.internal.core.AntClassLoader.loadClassPlugins(AntClassLoader.java:69)
    at org.eclipse.ant.internal.core.AntClassLoader.findClass(AntClassLoader.java:47)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    at org.eclipse.ant.core.AntRunner.run(AntRunner.java:510)
    at org.eclipse.ant.core.AntRunner.start(AntRunner.java:600)
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:193)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:386)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:549)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:504)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1236)
    at org.eclipse.equinox.launcher.Main.main(Main.java:1212)
Caused by: java.lang.NoClassDefFoundError: org/eclipse/swt/SWTError
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
    at java.lang.Class.getConstructor0(Class.java:2699)
    at java.lang.Class.newInstance0(Class.java:326)
    at java.lang.Class.newInstance(Class.java:308)
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadBundleActivator(AbstractBundle.java:141)
    ... 61 more
Caused by: java.lang.ClassNotFoundException: org.eclipse.swt.SWTError
    at org.eclipse.osgi.framework.internal.core.BundleLoader.findClassInternal(BundleLoader.java:483)
    at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:399)
    at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:387)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:87)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    ... 67 more
Root exception:
java.lang.NoClassDefFoundError: org/eclipse/swt/SWTError
```

I've already tried a couple of things after moving to the new infrastructure, with no avail:

 Use a different rt.jar (one coming from a windows JRE) for the PDE build using the bootclasspath property.

Changning the -os command line argument to: solaris

Is it at all possible to do a RCP build for a Windows application on a Unix machine?
If yes, is it necessary to change any parameters when launching the PDE build?

Note: We're using pluginbuilder to setup the PDE build.

答: Download eclipse delta pack, unzip it into your target eclipse before starting PDE build.</p>

Body:
We're trying to do an Eclipse PDE build for a RCP Application via Hudson/Jenkins. We were doing this so far successfully on a Windows machine (Hudson running on Windows Server 2003). We have decided to move our CI system to a unix machine.
When executing the same build on the unix machine our build fails with the following error:

!SESSION 2011-04-12 01:00:49.497 -----------------------------------------------
eclipse.buildId=unknown
java.version=1.6.0_23
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=win32, ARCH=sparc, WS=win32, NL=en_US
Framework arguments:  -application org.eclipse.ant.core.antRunner -buildfile /appl/midw/jenkins/jobs/AP_NAPF/workspace/TP/plugins/org.eclipse.pde.build_3.4.1.R34x_v20081217/scripts/build.xml main -Ddummy=true
Command-line arguments:  -ws win32 -os win32 -application org.eclipse.ant.core.antRunner -buildfile /appl/midw/jenkins/jobs/AP_NAPF/workspace/TP/plugins/org.eclipse.pde.build_3.4.1.R34x_v20081217/scripts/build.xml main -data /appl/midw/jenkins/jobs/AP_NAPF/workspace/ap_build/workspace -Ddummy=true

!ENTRY org.eclipse.osgi 4 0 2011-04-12 01:00:58.961
!MESSAGE An error occurred while automatically activating bundle org.eclipse.ui.workbench (687).
!STACK 0
org.osgi.framework.BundleException: The activator org.eclipse.ui.internal.WorkbenchPlugin for bundle org.eclipse.ui.workbench is invalid
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadBundleActivator(AbstractBundle.java:146)
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:980)
    at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:346)
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:265)
    at org.eclipse.osgi.framework.util.SecureAction.start(SecureAction.java:400)
    at org.eclipse.core.runtime.internal.adaptor.EclipseLazyStarter.postFindLocalClass(EclipseLazyStarter.java:111)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass(ClasspathManager.java:427)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.findLocalClass(DefaultClassLoader.java:193)
    at org.eclipse.osgi.framework.internal.core.BundleLoader.findLocalClass(BundleLoader.java:370)
    at org.eclipse.osgi.framework.internal.core.SingleSourcePackage.loadClass(SingleSourcePackage.java:33)
    at org.eclipse.osgi.framework.internal.core.BundleLoader.findClassInternal(BundleLoader.java:443)
    at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:399)
    at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:387)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:87)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.defineClass(DefaultClassLoader.java:165)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.defineClass(ClasspathManager.java:554)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findClassImpl(ClasspathManager.java:524)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClassImpl(ClasspathManager.java:455)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass_LockClassLoader(ClasspathManager.java:443)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass(ClasspathManager.java:423)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.findLocalClass(DefaultClassLoader.java:193)
    at org.eclipse.osgi.framework.internal.core.BundleLoader.findLocalClass(BundleLoader.java:370)
    at org.eclipse.osgi.framework.internal.core.BundleLoader.findClassInternal(BundleLoader.java:446)
    at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:399)
    at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:387)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:87)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    at org.eclipse.osgi.framework.internal.core.BundleLoader.loadClass(BundleLoader.java:315)
    at org.eclipse.osgi.framework.internal.core.BundleHost.loadClass(BundleHost.java:227)
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadBundleActivator(AbstractBundle.java:139)
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:980)
    at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:346)
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:265)
    at org.eclipse.osgi.framework.util.SecureAction.start(SecureAction.java:400)
    at org.eclipse.osgi.framework.internal.core.BundleHost.loadClass(BundleHost.java:234)
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadClass(AbstractBundle.java:1274)
    at org.eclipse.ant.core.AntCorePreferences$WrappedClassLoader.findClass(AntCorePreferences.java:115)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    at org.eclipse.ant.internal.core.AntClassLoader.loadClassPlugins(AntClassLoader.java:69)
    at org.eclipse.ant.internal.core.AntClassLoader.findClass(AntClassLoader.java:47)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    at org.eclipse.ant.core.AntRunner.run(AntRunner.java:510)
    at org.eclipse.ant.core.AntRunner.start(AntRunner.java:600)
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:193)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:386)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:549)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:504)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1236)
    at org.eclipse.equinox.launcher.Main.main(Main.java:1212)
Caused by: java.lang.NoClassDefFoundError: org/eclipse/swt/SWTError
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
    at java.lang.Class.getConstructor0(Class.java:2699)
    at java.lang.Class.newInstance0(Class.java:326)
    at java.lang.Class.newInstance(Class.java:308)
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadBundleActivator(AbstractBundle.java:141)
    ... 61 more
Caused by: java.lang.ClassNotFoundException: org.eclipse.swt.SWTError
    at org.eclipse.osgi.framework.internal.core.BundleLoader.findClassInternal(BundleLoader.java:483)
    at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:399)
    at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:387)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:87)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    ... 67 more
Root exception:
java.lang.NoClassDefFoundError: org/eclipse/swt/SWTError

I've already tried a couple of things after moving to the new infrastructure, with no avail:

 Use a different rt.jar (one coming from a windows JRE) for the PDE build using the bootclasspath property.

Changning the -os command line argument to: solaris

Is it at all possible to do a RCP build for a Windows application on a Unix machine?
If yes, is it necessary to change any parameters when launching the PDE build?

Note: We're using pluginbuilder to setup the PDE build.


来源: stackexchange

问:
Angular @Input() not binding and not working in Angular 7
I have a master template with a component like this:

```<code>   <h2>My Heroes</h2>
<ul class="heroes">
  <li *ngFor="let hero of heroes"
    [class.selected]="hero === selectedHero"
    (click)="onSelect(hero)">
    <span class="badge">{{hero.id}}</span> {{hero.name}}
  </li>
</ul>

<app-hero-detail [hero]="selectedHero"></app-hero-detail>]
</code>```

The Master component is like this:

```<code>import { Component, OnInit } from '@angular/core';

import { Hero } from '../hero';
import { HeroService } from '../hero.service';

@Component({
  selector: 'app-heroes',
  templateUrl: './heroes.component.html',
  styleUrls: ['./heroes.component.css']
})
export class HeroesComponent implements OnInit {

  public selectedHero: Hero;

  heroes: Hero[];

  constructor(private heroService: HeroService) { }

  ngOnInit() {
    this.getHeroes();
  }

  onSelect(hero: Hero): void {

    this.selectedHero = hero;
  }

  getHeroes(): void {
    this.heroService.getHeroes()
        .subscribe(heroes => this.heroes = heroes);
  }
}
</code>```

The Master template is getting data from a service.

On clicking the master's element in list the Child details are displayed.

Using this in master:

```<code> <li *ngFor="let hero of heroes"
[class.selected]="hero === selectedHero"
(click)="onSelect(hero)">
</code>```

and binding in to

```<code><app-hero-detail [hero]="selectedHero"></app-hero-detail>]
</code>```

But I am getting this error in the console.

ERROR TypeError: Cannot read property 'name' of undefined
      at HeroDetailComponent.push../src/app/hero-detail/hero-detail.component.ts.HeroDetailComponent.ngOnInit
  (hero-detail.component.ts:19)
      at checkAndUpdateDirectiveInline (core.js:22099)
      at checkAndUpdateNodeInline (core.js:23363)
      at checkAndUpdateNode (core.js:23325)
      at debugCheckAndUpdateNode (core.js:23959)
      at debugCheckDirectivesFn (core.js:23919)
      at Object.eval [as updateDirectives] (HeroesComponent.html:10)
      at Object.debugUpdateDirectives [as updateDirectives] (core.js:23911)
      at checkAndUpdateView (core.js:23307)
      at callViewAction (core.js:23548)

My child component is like this:

```<code>import { Component, OnInit, Input } from '@angular/core';
import { Hero } from '../hero';
import { HeroService } from '../hero.service';

@Component({
  selector: 'app-hero-detail',
  templateUrl: './hero-detail.component.html',
  styleUrls: ['./hero-detail.component.css']
})
export class HeroDetailComponent implements OnInit {

  @Input() hero: Hero;

  heroes: Hero[];

  constructor(private heroService: HeroService) {  }
  i: string;
  ngOnInit() {
    this.i = this.hero.name

    this.getHeroes();

  }
  getHeroes(): void {

    this.heroService.getHeroes(this.i)
      .subscribe(heroes => this.heroes = heroes);
  }

}
</code>```

Please Note: I am using the following to bind:

```<code>@Input() hero: Hero; // in child component to parent template
</code>```

答:
use the ngOnChanges to check whether the input value is set</p>

```<code>  ngOnChanges() {
    if(!this.hero) return null;
    this.i = this.hero.name

    this.getHeroes();

  }
</code>```

ContentLicense: CC BY-SA 4.0

Body:
I have a master template with a component like this:

My Heroes

    {{hero.id}} {{hero.name}}

<app-hero-detail [hero]="selectedHero"></app-hero-detail>]

The Master component is like this:

import { Component, OnInit } from '@angular/core';

import { Hero } from '../hero';
import { HeroService } from '../hero.service';

@Component({
  selector: 'app-heroes',
  templateUrl: './heroes.component.html',
  styleUrls: ['./heroes.component.css']
})
export class HeroesComponent implements OnInit {

  public selectedHero: Hero;

  heroes: Hero[];

  constructor(private heroService: HeroService) { }

  ngOnInit() {
    this.getHeroes();
  }

  onSelect(hero: Hero): void {

    this.selectedHero = hero;
  }

  getHeroes(): void {
    this.heroService.getHeroes()
        .subscribe(heroes => this.heroes = heroes);
  }
}

The Master template is getting data from a service.

On clicking the master's element in list the Child details are displayed.

Using this in master:

and binding in to

<app-hero-detail [hero]="selectedHero"></app-hero-detail>]

But I am getting this error in the console.

ERROR TypeError: Cannot read property 'name' of undefined
      at HeroDetailComponent.push../src/app/hero-detail/hero-detail.component.ts.HeroDetailComponent.ngOnInit
  (hero-detail.component.ts:19)
      at checkAndUpdateDirectiveInline (core.js:22099)
      at checkAndUpdateNodeInline (core.js:23363)
      at checkAndUpdateNode (core.js:23325)
      at debugCheckAndUpdateNode (core.js:23959)
      at debugCheckDirectivesFn (core.js:23919)
      at Object.eval [as updateDirectives] (HeroesComponent.html:10)
      at Object.debugUpdateDirectives [as updateDirectives] (core.js:23911)
      at checkAndUpdateView (core.js:23307)
      at callViewAction (core.js:23548)

My child component is like this:

import { Component, OnInit, Input } from '@angular/core';
import { Hero } from '../hero';
import { HeroService } from '../hero.service';

@Component({
  selector: 'app-hero-detail',
  templateUrl: './hero-detail.component.html',
  styleUrls: ['./hero-detail.component.css']
})
export class HeroDetailComponent implements OnInit {

  @Input() hero: Hero;

  heroes: Hero[];

  constructor(private heroService: HeroService) {  }
  i: string;
  ngOnInit() {
    this.i = this.hero.name

    this.getHeroes();

  }
  getHeroes(): void {

    this.heroService.getHeroes(this.i)
      .subscribe(heroes => this.heroes = heroes);
  }

}

Please Note: I am using the following to bind:

@Input() hero: Hero; // in child component to parent template

Body:
use the ngOnChanges to check whether the input value is set

  ngOnChanges() {
    if(!this.hero) return null;
    this.i = this.hero.name

    this.getHeroes();

  }


答:
onInit, the hero may not be defined, its getting populated after the component has been initialized. You can try using

```<code>@Input() set hero (value) {
   if(value) {
      this.i = this.hero.name;
   }
}
</code>```

Title: Angular @Input() not binding and not working in Angular 7

Body:
onInit, the hero may not be defined, its getting populated after the component has been initialized. You can try using

@Input() set hero (value) {
   if(value) {
      this.i = this.hero.name;
   }
}


问:
How to test a routing handler calling via mock from express
I'm unit-testing some code of mine in nodejs that works with express.
While it seems obvious, I want to test that my routes are calling the right handler functions.

I'm using jest to create a mock function for the handler function.
While I successfully tried to test that a function is called inside another function, I cannot seem to test that a function (handler) is called from express get of post.
Let's see an examplee:

fruits.js

function orange (req,res,next) {res.status(200)} ;
module.exports = {orange}
```

<p>app.js</p>

<pre class="lang-js prettyprint-override"><code>const fruits = require('./fruits')
const express = require('express');
const app = express();

app.get('/fruits', fruits.orange);

module.exports = { app };
</code>```

When I'm trying to test (with jest) that GET request (with the help of axios module) to /fruits is calling orange(), altough actually orange() works, it won't be saved as a calling with a mock function cover of spy cover.

How can I test that orange() has been called from the GET request ?

答:
Try using supertest with Jest</p>

```<code>const app = require('../app') //path to app.js
const request = require('supertest')

test('Upload Info Endpoint', async() => {
        await request(app).get('/fruits')
        .expect(resp.body.field).toMatch(mocked_field_value)
 });
</code>```

Body:
I'm unit-testing some code of mine in nodejs that works with express.
While it seems obvious, I want to test that my routes are calling the right handler functions.

I'm using jest to create a mock function for the handler function.
While I successfully tried to test that a function is called inside another function, I cannot seem to test that a function (handler) is called from express get of post.
Let's see an examplee:

fruits.js

function orange (req,res,next) {res.status(200)} ;
module.exports = {orange}

app.js

const fruits = require('./fruits')
const express = require('express');
const app = express();

app.get('/fruits', fruits.orange);

module.exports = { app };

When I'm trying to test (with jest) that GET request (with the help of axios module) to /fruits is calling orange(), altough actually orange() works, it won't be saved as a calling with a mock function cover of spy cover.

How can I test that orange() has been called from the GET request ?

Body:
Try using supertest with Jest

const app = require('../app') //path to app.js
const request = require('supertest')

test('Upload Info Endpoint', async() => {
        await request(app).get('/fruits')
        .expect(resp.body.field).toMatch(mocked_field_value)
 });


问:
How to give specific width to HTML table and columns
I have created an HTML table with JSON data which I am dividing into four columns to show up on display Screen, and at one go showing 5 rows then after 5 seconds next five row, This how my table is working

Now I have to show that Table on a display screen which has a resolution of 1336*768 soi am trying to give the full with so that it fitted to screen without any scroll

Due to Some reasons I want to give width to my columns also but that too is not taking the width, I don't know what I am doing wrong It is coming

Code

$(document).ready(function() {

  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 7",
    "SellingPrice": 1125
  }, {
    "Item Name": "FOUR SEAZON CLASSIC CHENNIN BLANC B",
    "SellingPrice": 225
  }, {
    "Item Name": "BIG BANAYAN CARBINET SAUVIGNON 750",
    "SellingPrice": 1125
  }, {
    "Item Name": "BIG BANAYAN CARBINET SAUVIGNON BY G",
    "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() {
    // Any TRs that are not hidden and not already shown get "already-shown" applied
    $("tr:not(.hidden):not(.already-shown)").addClass("already-shown");
    // Then your previous code
    $(".hidden:lt(5)").removeClass("hidden"); // this one is to hide previous 5 rows and show next five
  }

  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"
      }); //ading class
      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: 1.1rem;
  font-weight: bold;
  white-space: nowrap;
  width: 100%;
}

td:nth-child(1),
td:nth-child(3),
td:nth-child(5),
td:nth-child(7) {
  width: 50px;
  /*change*/
  max-width: 50px;
  /*new add*/
}

.color1 {
  background: #4AD184;
}

.color2 {
  background: #EA69EF;
}

.color3 {
  background: #E1A558;
}

.color4 {
  background: #F4F065;
}

/* added .already-shown to have the same properties as hidden */

.hidden,
.already-shown {
  display: none;
}</code>```

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

```

EDIT

I am trying to fix the column width of itemname while doing that the texts are over lapping

答:
your css style have extra comma in td:child element

```<code>td:nth-child(1),
td:nth-child(3),,  <----- look here
td:nth-child(5),,  <----- look here
td:nth-child(7) {
  width: 10px;
}
</code>```

Why not just set table column width base on td element. like this

```<code>td {
  width: 10px;
}
</code>```

else you can try individual column width

```<code>td:nth-child(1),
td:nth-child(3),
td:nth-child(5),
td:nth-child(7) {
  width: 10px;
}
</code>```

Body:
I have created an HTML table with JSON data which I am dividing into four columns to show up on display Screen, and at one go showing 5 rows then after 5 seconds next five row, This how my table is working

Now I have to show that Table on a display screen which has a resolution of 1336*768 soi am trying to give the full with so that it fitted to screen without any scroll

Due to Some reasons I want to give width to my columns also but that too is not taking the width, I don't know what I am doing wrong It is coming

Code

$(document).ready(function() {

  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 7",
    "SellingPrice": 1125
  }, {
    "Item Name": "FOUR SEAZON CLASSIC CHENNIN BLANC B",
    "SellingPrice": 225
  }, {
    "Item Name": "BIG BANAYAN CARBINET SAUVIGNON 750",
    "SellingPrice": 1125
  }, {
    "Item Name": "BIG BANAYAN CARBINET SAUVIGNON BY G",
    "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() {
    // Any TRs that are not hidden and not already shown get "already-shown" applied
    $("tr:not(.hidden):not(.already-shown)").addClass("already-shown");
    // Then your previous code
    $(".hidden:lt(5)").removeClass("hidden"); // this one is to hide previous 5 rows and show next five
  }

  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"
      }); //ading class
      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: 1.1rem;
  font-weight: bold;
  white-space: nowrap;
  width: 100%;
}

td:nth-child(1),
td:nth-child(3),
td:nth-child(5),
td:nth-child(7) {
  width: 50px;
  /*change*/
  max-width: 50px;
  /*new add*/
}

.color1 {
  background: #4AD184;
}

.color2 {
  background: #EA69EF;
}

.color3 {
  background: #E1A558;
}

.color4 {
  background: #F4F065;
}

/* added .already-shown to have the same properties as hidden */

.hidden,
.already-shown {
  display: none;
}

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

EDIT

I am trying to fix the column width of itemname while doing that the texts are over lapping

Body:
your css style have extra comma in td:child element

td:nth-child(1),
td:nth-child(3),,  <----- look here
td:nth-child(5),,  <----- look here
td:nth-child(7) {
  width: 10px;
}

Why not just set table column width base on td element. like this

td {
  width: 10px;
}

else you can try individual column width

td:nth-child(1),
td:nth-child(3),
td:nth-child(5),
td:nth-child(7) {
  width: 10px;
}


问:
Is It possible to change the background and text colour of a tooltip message without using javascript?
```<code><span class="fa fa-info-circle" data-toggle="tooltip"
                            style="color:white; background-color: orange"
                            title="captain teemo"></span>
</code>```

It only changes the icon of the tooltip not the message when the mouse cursor hovers on it

答: You cannot change the default tooltip appearance using simple CSS since it is browser/OS-dependent. If you do want to change the appearance of the tooltip I suggest you use javascript or a third party library instead of using the default tooltip generated from your browser/OS.</p>


问:
I want to plus the number form string datatype
I have the following input as string:

```<code>Num: 12345
</code>```

I would like to print out the sum of digits from the input (1+2+3+4+5 = 15):

```<code>total:15
</code>```

I tried, but there is a problem with atoi() in the for loop and I got an error:

[Error] invalid conversion from 'char' to 'const char*'

How can I fix that or how can I resolve it in an easier way?

```<code> #include <stdio.h>
 #include <ctype.h>
 #include <stdlib.h>
 #include <string.h>

 char numstr[100];
 int total = 0;

 main(){
     printf("Num:");
     scanf("%s", numstr);

     for(int i = 0; i < strlen(numstr); i++){
         total += atoi(numstr[i]);
     }
     printf("%d", total);
 }
</code>```

答:
atoi() does not do what you think it does.

A possible way to achieve what you want is to use atoi(), or better, strtol() to convert the user input to integer type, and then use the modulo operaptor to extract each digit and add them.

```<code> #include <stdio.h>
 #include <ctype.h>
 #include <stdlib.h>
 #include <string.h>

 int main(void){                     //correct signature

     int total=0;                    // no need to be global
     char numstr[100] = {0};         // same
     int ret = -1;

     printf("Num:");
     ret = scanf("%99s",numstr);
     if (ret != 1){                    // basic sanity check for scanf
         printf("Error in scanning\n");
         exit (-1);
     }

     long int converted = strtol(numstr, NULL, 10);   // convert to integer
     printf("%ld\n\n", converted);

     for (int i = 0; converted; i++){

         total += converted %10;                // add the digit
         converted /= 10;                       // reduce the last added digit
     }

     printf("%d",total);
     return 0;                               // return 0 is implicit for `main()`, anyways
 }
</code>```

Body:
I have the following input as string:

Num: 12345

I would like to print out the sum of digits from the input (1+2+3+4+5 = 15):

total:15

I tried, but there is a problem with atoi() in the for loop and I got an error:

[Error] invalid conversion from 'char' to 'const char*'

How can I fix that or how can I resolve it in an easier way?

 #include <stdio.h>
 #include <ctype.h>
 #include <stdlib.h>
 #include <string.h>

 char numstr[100];
 int total = 0;

 main(){
     printf("Num:");
     scanf("%s", numstr);

     for(int i = 0; i < strlen(numstr); i++){
         total += atoi(numstr[i]);
     }
     printf("%d", total);
 }

Body:
atoi() does not do what you think it does.

A possible way to achieve what you want is to use atoi(), or better, strtol() to convert the user input to integer type, and then use the modulo operaptor to extract each digit and add them.

 #include <stdio.h>
 #include <ctype.h>
 #include <stdlib.h>
 #include <string.h>

 int main(void){                     //correct signature

     int total=0;                    // no need to be global
     char numstr[100] = {0};         // same
     int ret = -1;

     printf("Num:");
     ret = scanf("%99s",numstr);
     if (ret != 1){                    // basic sanity check for scanf
         printf("Error in scanning\n");
         exit (-1);
     }

     long int converted = strtol(numstr, NULL, 10);   // convert to integer
     printf("%ld\n\n", converted);

     for (int i = 0; converted; i++){

         total += converted %10;                // add the digit
         converted /= 10;                       // reduce the last added digit
     }

     printf("%d",total);
     return 0;                               // return 0 is implicit for `main()`, anyways
 }


问:
Stored procedure returns null as output parameter
I have stored procedure, which works great in MS SQL management studio.

When I try to use it in VS rows returns fine, but value of output parameters is NULL.

SqlCommand cmd = new SqlCommand("proc_name", conn);
cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.Add(new SqlParameter("@p_SomeVal", SqlDbType.Int));
cmd.Parameters["@p_SomeVal"].Direction = ParameterDirection.Output;

rdr = cmd.ExecuteReader();
//...process rows...

if (cmd.Parameters["@p_SomeVal"].Value != null)
SomeVal = (int)cmd.Parameters["@p_SomeVal"].Value;
```

<p>cmd.ExecuteNonQuery(); Has the same result.</p>

```USE [db_name]
GO

DECLARE @return_value int,
    @p_SomeValue int

EXEC    @return_value = [dbo].[Proc_name]
    @p_InputVal = N'aa',
    @p_SomeValue = @p_SomeValue OUTPUT

SELECT  @p_SomeValue as N'p_SomeValue'

SELECT  'Return Value' = @return_value

GO
```

答:
Salaam,
You can check if output is null and convert like this.

```<code>returnedSQLParameter.Value != DBNull.Value? (int)returnedSQLParameter.Value : 0;
</code>```

Because it is returning DBNull.value when output sent NULL from stored procedure.

ContentLicense: CC BY-SA 3.0

Body:
I have stored procedure, which works great in MS SQL management studio.

When I try to use it in VS rows returns fine, but value of output parameters is NULL.

SqlCommand cmd = new SqlCommand("proc_name", conn);
cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.Add(new SqlParameter("@p_SomeVal", SqlDbType.Int));
cmd.Parameters["@p_SomeVal"].Direction = ParameterDirection.Output;

rdr = cmd.ExecuteReader();
//...process rows...

if (cmd.Parameters["@p_SomeVal"].Value != null)
SomeVal = (int)cmd.Parameters["@p_SomeVal"].Value;

cmd.ExecuteNonQuery(); Has the same result.

USE [db_name]
GO

DECLARE @return_value int,
    @p_SomeValue int

EXEC    @return_value = [dbo].[Proc_name]
    @p_InputVal = N'aa',
    @p_SomeValue = @p_SomeValue OUTPUT

SELECT  @p_SomeValue as N'p_SomeValue'

SELECT  'Return Value' = @return_value

GO

Body:
Salaam,
You can check if output is null and convert like this.

returnedSQLParameter.Value != DBNull.Value? (int)returnedSQLParameter.Value : 0;

Because it is returning DBNull.value when output sent NULL from stored procedure.


答:
Why don't you add a width on the table in the css, like the following</p>

```<code>table {
width: 100%;
}
</code>```

Title: How to give specific width to HTML table and columns

Body:
Why don't you add a width on the table in the css, like the following

table {
width: 100%;
}


问:
Constructor injection into IDesignTimeDbContextFactory
I'm attempting to use migrations EFCore2.0 in a .NET standard 2.0 class library, and so far I have something like

```<code>public class SomeContextFactory : IDesignTimeDbContextFactory<SomeContext>
{
    private Configuration _configuration;

    public SomeContextFactory(Configuration configuration)
    {
        _configuration = configuration;
    }

    public SomeContext CreateDbContext(string[] args)
    {
        var optionsBuilder = new DbContextOptionsBuilder<SomeContext>();

        optionsBuilder.UseSqlServer(_configuration.ConnectionString);

        return new SomeContext(optionsBuilder.Options);
    }
}

public class SomeContext : DbContext
{
    public DbSet<SomeDbModel> Some { get; set; }

    public SomeContext(DbContextOptions<SomeContext> options) : base(options)
    {
    }
}
</code>```

The point is that the connection string is different depending on the environment (dev,test,prod), and migrations should be performed on the database specified by the Configuration.

How do instruct migrations to inject Configuration into SomeContextFactory?

答:
By design, the IDesignTimeDbContextFactory isn't supposed to work with DI.
One way to achieve this would be:

```<code>public class AppDbContextFactory : IDesignTimeDbContextFactory<AppDbContext>
{
  public AppDbContext CreateDbContext(params string[] args)
  {
    var options = new DbContextOptionsBuilder<AppDbContext>();
    var config = GetAppConfiguration();
    options.UseSqlServer(config.GetConnectionString("DesignTimeAppDbConnection"));

    return new AppDbContext(options.Options);
  }

  IConfiguration GetAppConfiguration()
  {
    var environmentName =
              Environment.GetEnvironmentVariable(
                  "ASPNETCORE_ENVIRONMENT");

    var dir = Directory.GetParent(AppContext.BaseDirectory);

    if(EnvironmentName.Development.Equals(environmentName,
        StringComparison.OrdinalIgnoreCase))
    {
      var depth = 0;
      do
        dir = dir.Parent;
      while (++depth < 5 && dir.Name != "bin");
      dir = dir.Parent;
    }

    var path = dir.FullName;

    var builder = new ConfigurationBuilder()
            .SetBasePath(path)
            .AddJsonFile("appsettings.json")
            .AddJsonFile($"appsettings.{environmentName}.json", true)
            .AddEnvironmentVariables();

    return builder.Build();
  }
}
</code>```

Body:
I'm attempting to use migrations EFCore2.0 in a .NET standard 2.0 class library, and so far I have something like

public class SomeContextFactory : IDesignTimeDbContextFactory<SomeContext>
{
    private Configuration _configuration;

    public SomeContextFactory(Configuration configuration)
    {
        _configuration = configuration;
    }

    public SomeContext CreateDbContext(string[] args)
    {
        var optionsBuilder = new DbContextOptionsBuilder<SomeContext>();

        optionsBuilder.UseSqlServer(_configuration.ConnectionString);

        return new SomeContext(optionsBuilder.Options);
    }
}

public class SomeContext : DbContext
{
    public DbSet<SomeDbModel> Some { get; set; }

    public SomeContext(DbContextOptions<SomeContext> options) : base(options)
    {
    }
}

The point is that the connection string is different depending on the environment (dev,test,prod), and migrations should be performed on the database specified by the Configuration.

How do instruct migrations to inject Configuration into SomeContextFactory?

Body:
By design, the IDesignTimeDbContextFactory isn't supposed to work with DI.
One way to achieve this would be:

public class AppDbContextFactory : IDesignTimeDbContextFactory<AppDbContext>
{
  public AppDbContext CreateDbContext(params string[] args)
  {
    var options = new DbContextOptionsBuilder<AppDbContext>();
    var config = GetAppConfiguration();
    options.UseSqlServer(config.GetConnectionString("DesignTimeAppDbConnection"));

    return new AppDbContext(options.Options);
  }

  IConfiguration GetAppConfiguration()
  {
    var environmentName =
              Environment.GetEnvironmentVariable(
                  "ASPNETCORE_ENVIRONMENT");

    var dir = Directory.GetParent(AppContext.BaseDirectory);

    if(EnvironmentName.Development.Equals(environmentName,
        StringComparison.OrdinalIgnoreCase))
    {
      var depth = 0;
      do
        dir = dir.Parent;
      while (++depth < 5 && dir.Name != "bin");
      dir = dir.Parent;
    }

    var path = dir.FullName;

    var builder = new ConfigurationBuilder()
            .SetBasePath(path)
            .AddJsonFile("appsettings.json")
            .AddJsonFile($"appsettings.{environmentName}.json", true)
            .AddEnvironmentVariables();

    return builder.Build();
  }
}


问:
unable to create file ... Permission denied
i am currently working on windows.

Sometimes i have problems when i try :

```<code>git checkout origin develop
</code>```

i have this error :
error: unable to create file .... : Permission denied

"git status" show me the file in error not staged so i have to commit

What do i have to check ?

i tried to do this command line on my computer :

```<code>chown -R username directory
</code>```

We are severals people to work on a git repository and they have the problem too.

thanks for you help

答: I was facing the same issue. If your code is running, Stop it (i.e close the terminal on which npm run *** is working) and close Visual Studio. Re-open it and again run the command git checkout develop . It worked for me.</p>

Body:
i am currently working on windows.

Sometimes i have problems when i try :

git checkout origin develop

i have this error :
error: unable to create file .... : Permission denied

"git status" show me the file in error not staged so i have to commit

What do i have to check ?

i tried to do this command line on my computer :

chown -R username directory

We are severals people to work on a git repository and they have the problem too.

thanks for you help


问:
What is the difference between model.training = False and model.param.require_grad = False
What is the difference between these two:

```<code>model.training = False
</code>```

and

```<code>for param in model.parameters():
    param.require_grad = False
</code>```

答:
model.training = False sets the module in evaluation mode, i.e.,

```<code>if model.training == True:
    # Train mode
if model.training == False:
    # Evaluation mode
</code>```

So, effectively layers like dropout, batchnorm etc. which behave different on the train and test procedures know what is going on and hence can behave accordingly.

while

```<code>for param in model.parameters():
    param.require_grad = False
</code>```

freeze the layers so that these layers are not trainable.

The basic idea is that all models have a function model.children() which returns it’s layers. Within each layer, there are parameters (or weights), which can be obtained using .param() on any children (i.e. layer). Now, every parameter has an attribute called requires_grad which is by default True. True means it will be backpropagrated and hence to freeze a layer you need to set requires_grad to False for all parameters of a layer.

Body:
What is the difference between these two:

model.training = False

and

for param in model.parameters():
    param.require_grad = False

Body:
model.training = False sets the module in evaluation mode, i.e.,

if model.training == True:
    # Train mode
if model.training == False:
    # Evaluation mode

So, effectively layers like dropout, batchnorm etc. which behave different on the train and test procedures know what is going on and hence can behave accordingly.

while

for param in model.parameters():
    param.require_grad = False

freeze the layers so that these layers are not trainable.

The basic idea is that all models have a function model.children() which returns it’s layers. Within each layer, there are parameters (or weights), which can be obtained using .param() on any children (i.e. layer). Now, every parameter has an attribute called requires_grad which is by default True. True means it will be backpropagrated and hence to freeze a layer you need to set requires_grad to False for all parameters of a layer.


问:
Leaving Github, how to change the origin of a Git repo?
I'm hosting a project in Github, but now I purchased a plan with Dreamhost that includes shell access and Git.

```<code>      Github [Origin]
       /         \
  pull/           \pull
     /push     push\
    /               \
Laptop           Dreamhost
(cloned)          (cloned)
</code>```

I would like to delete my repo from Github, and starting push directly to DH.

How do I change origin in my Laptop, and should I delete the origin in Dreamhost?

答:
The easiest way is:

```<code>$ git config remote.origin.url <Dreamhost-git-URL>
</code>```

You show the remotes after this:

```<code>$ git remote -v
origin Dreamhost-git-URL (fetch)
origin Dreamhost-git-URL (push)
</code>```

ContentLicense: CC BY-SA 2.5

Body:
I'm hosting a project in Github, but now I purchased a plan with Dreamhost that includes shell access and Git.

      Github [Origin]
       /         \
  pull/           \pull
     /push     push\
    /               \
Laptop           Dreamhost
(cloned)          (cloned)

I would like to delete my repo from Github, and starting push directly to DH.

How do I change origin in my Laptop, and should I delete the origin in Dreamhost?

Body:
The easiest way is:

$ git config remote.origin.url <Dreamhost-git-URL>

You show the remotes after this:

$ git remote -v
origin Dreamhost-git-URL (fetch)
origin Dreamhost-git-URL (push)


问:
How to create a regular expression to find out repeated character in string?
Eg:

HelloWorld - repeated characters are 5 (l is repeating 3 times and o is repeating 2 times)

Smart2000,  repeated characters = 3?(0 is repeating 3 times)

Smart@200@12, repeated characters = 6

I tried with iterating over string

Here is my code with string iteration to find out the repeated character in string.

```<code>func countRepeatDigitsIn(keyword : String) -> Int
{
    // To keep track of processed symbols
    var uniqueCharacters = ""
    var repeatCharacterCount = 0

    for char in keyword.uppercased() {
        let alphabet = String(char)

        // If this is already counted, skip it
        if (uniqueCharacters.contains(alphabet))
        {
            repeatCharacterCount += 1
        }

        // Otherwise, add it to processed symbols
        uniqueCharacters += alphabet
    }

    return repeatCharacterCount
}
</code>```

答:
Here's a fun chain of reductions and filters on the characters of the string.

```<code>func countRepeatDigitsIn(keyword : String) -> Int {
    let total = Array(keyword.uppercased()).reduce(into: [Character : Int]()) { $0[$1, default: 0] += 1 }.filter { $0.value > 1 }.reduce(0) { $0 + $1.value }

    return total
}

for text in ["HelloWorld", "Smart2000", "Smart@200@12"] {
    print(text, countRepeatDigitsIn(keyword: text))
}
</code>```

The first reduce builds a dictionary where the keys are characters and the values is the count for the character. Then the filter removes characters only found once. The second reduce adds the remaining counts.

Body:
Eg:

HelloWorld - repeated characters are 5 (l is repeating 3 times and o is repeating 2 times)

Smart2000,  repeated characters = 3?(0 is repeating 3 times)

Smart@200@12, repeated characters = 6

I tried with iterating over string

Here is my code with string iteration to find out the repeated character in string.

func countRepeatDigitsIn(keyword : String) -> Int
{
    // To keep track of processed symbols
    var uniqueCharacters = ""
    var repeatCharacterCount = 0

    for char in keyword.uppercased() {
        let alphabet = String(char)

        // If this is already counted, skip it
        if (uniqueCharacters.contains(alphabet))
        {
            repeatCharacterCount += 1
        }

        // Otherwise, add it to processed symbols
        uniqueCharacters += alphabet
    }

    return repeatCharacterCount
}

Body:
Here's a fun chain of reductions and filters on the characters of the string.

func countRepeatDigitsIn(keyword : String) -> Int {
    let total = Array(keyword.uppercased()).reduce(into: [Character : Int]()) { $0[$1, default: 0] += 1 }.filter { $0.value > 1 }.reduce(0) { $0 + $1.value }

    return total
}

for text in ["HelloWorld", "Smart2000", "Smart@200@12"] {
    print(text, countRepeatDigitsIn(keyword: text))
}

The first reduce builds a dictionary where the keys are characters and the values is the count for the character. Then the filter removes characters only found once. The second reduce adds the remaining counts.


问:
Enable only createdAt time stamp and ignore updatedAt timestamp in Sequelize
I am trying to create some records into table with only the createdAt column filled. I want the updatedAt column to not exist how ever when i create a model it automatically generates the createdAt and updatedAt timestamps.

I tried to use timestamps : false but the createdAt column contains empty values.

```<code>const MyTable = sequelize.define(
  'my_table',
  {
    id: {
      type: DataTypes.INTEGER(11),allowNull: false,
      primaryKey: true,autoIncrement: true,
    },
    person_name: {type: DataTypes.STRING(255),allowNull: false},
    created: {type: DataTypes.DATE,allowNull: true},
  },
  {
    tableName: 'my_table',
    timestamps: false,
    createdAt: 'created',
  },
);
</code>```

Is it possible to fix this issue in the model itself without doing any change in the query ?

答:
According to the documentation on Init, you'll wanna leave the timestamps feature turned on, but configure your model to not use updatedAt.

Here's an edited version of the options object in your sample code that should give you what you are looking for:

```<code>  {
    tableName: 'my_table',
    updatedAt: false,
  }
</code>```

NB: The docs say "Timestamps must be true", which might indicate why it wasn't working the way it is in the sample you provided.

Cheers!

Body:
I am trying to create some records into table with only the createdAt column filled. I want the updatedAt column to not exist how ever when i create a model it automatically generates the createdAt and updatedAt timestamps.

I tried to use timestamps : false but the createdAt column contains empty values.

const MyTable = sequelize.define(
  'my_table',
  {
    id: {
      type: DataTypes.INTEGER(11),allowNull: false,
      primaryKey: true,autoIncrement: true,
    },
    person_name: {type: DataTypes.STRING(255),allowNull: false},
    created: {type: DataTypes.DATE,allowNull: true},
  },
  {
    tableName: 'my_table',
    timestamps: false,
    createdAt: 'created',
  },
);

Is it possible to fix this issue in the model itself without doing any change in the query ?

Body:
According to the documentation on Init, you'll wanna leave the timestamps feature turned on, but configure your model to not use updatedAt.

Here's an edited version of the options object in your sample code that should give you what you are looking for:

  {
    tableName: 'my_table',
    updatedAt: false,
  }

NB: The docs say "Timestamps must be true", which might indicate why it wasn't working the way it is in the sample you provided.

Cheers!


问:
How can I read an audio file using streams?
I am currently looking for away to stream audio-files. I'd like to read x amounts of seconds from a given .wav file, do my analysis task and repeat.....

Here is some code to get the idea of what i want:

```<code>`read_x_seconds = 30
 file_length_in_min = 15
 for x in range(file_length_in_min * (60 / read_x_seconds)):
    y, fs = librosa.core.load(FILENAME, offset=x * read_x_seconds,
    duration=read_x_seconds)
    do_analysis(y, fs)`
</code>```

答:
Assuming we're considering a case of reading a chunk of local WAV file:

```<code>import wave
import numpy as np

def read_wav_part_from_local(path: str, start_s: float, duration_s: float):
    with wave.open(path, mode='rb') as wavread:
        fs = wavread.getframerate()
        start = int(start_s * fs)
        duration = int(duration_s * fs)
        wavread.setpos(start)
        wav_bytes = wavread.readframes(duration)

        if wavread.getsampwidth() == 2:
            dtype = 'int16'
        elif wavread.getsampwidth() == 4:
            dtype = 'int32'
        else:
            raise NotImplemented('I give up!')

        wav_array = np.frombuffer(wav_bytes, dtype=dtype)
        return wav_array, fs
</code>```

How to use it:

```<code>audio_chunk, fs = read_wav_part_from_local('your.wav', offset_in_s, duration_in_s)
</code>```

Body:
I am currently looking for away to stream audio-files. I'd like to read x amounts of seconds from a given .wav file, do my analysis task and repeat.....

Here is some code to get the idea of what i want:

`read_x_seconds = 30
 file_length_in_min = 15
 for x in range(file_length_in_min * (60 / read_x_seconds)):
    y, fs = librosa.core.load(FILENAME, offset=x * read_x_seconds,
    duration=read_x_seconds)
    do_analysis(y, fs)`

Body:
Assuming we're considering a case of reading a chunk of local WAV file:

import wave
import numpy as np

def read_wav_part_from_local(path: str, start_s: float, duration_s: float):
    with wave.open(path, mode='rb') as wavread:
        fs = wavread.getframerate()
        start = int(start_s * fs)
        duration = int(duration_s * fs)
        wavread.setpos(start)
        wav_bytes = wavread.readframes(duration)

        if wavread.getsampwidth() == 2:
            dtype = 'int16'
        elif wavread.getsampwidth() == 4:
            dtype = 'int32'
        else:
            raise NotImplemented('I give up!')

        wav_array = np.frombuffer(wav_bytes, dtype=dtype)
        return wav_array, fs

How to use it:

audio_chunk, fs = read_wav_part_from_local('your.wav', offset_in_s, duration_in_s)


问:
Unsupported media type using RestSharp library
I start using RestSharp library to connect my Windows Forms application with web.

I created a method like this:

```<code>public static bool WebRequest(string route, string token, Method method, string model)
{
    var client = new RestClient("myapiurl");
    var request = new RestRequest(route, method);

    //"model" is a json
    request.AddParameter("application/json", model, ParameterType.GetOrPost);
    request.AddHeader("Accept", "application/json");
    request.AddHeader("Authorization", "Bearer " + token);
    request.RequestFormat = DataFormat.Json;

    IRestResponse response = client.Execute(request);

    var content = response.Content;

    return true;
}
</code>```

The request has 3 parameters:

```<code>{ application/json={ "CommunicationType":4854,"JobNumber":55555,"NotificationAddress":"(714) 978-9788","CreatedBy":"user@mail.com","IsDeleted":false } }
{ Accept=application/json }
{ Authorization=Bearer dasjd... }
</code>```

But the response always returns:

StatusCode: UnsupportedMediaType

I didn't see anything wrong in my request, can someone see what is wrong?

Regards

答:
Add need to add  content type in header

```<code>request.AddHeader("content-type", "application/json");
</code>```

get reference GetOrPost:ParameterTypes for RestRequest

RequestBody If this parameter is set, its value will be sent as the
  body of the request. Only one RequestBody parameter is accepted - the
  first one.

The name of the parameter will be used as the Content-Type header for
  the request.

RequestBody does not work on GET or HEAD Requests, as they do not
  actually send a body.

If you have GetOrPost parameters as well, they will overwrite the
  RequestBody - RestSharp will not combine them but it will instead
  throw the RequestBody parameter away.

It is recommended to use AddJsonBody or AddXmlBody methods instead of
  AddParameter with type BodyParameter. Those methods will set the
  proper request type and do the serialization work for you.

I think you need to add

```<code>request.AddJsonBody(model); // AddJsonBody serializes the object automatically
</code>```

Body:
I start using RestSharp library to connect my Windows Forms application with web.

I created a method like this:

public static bool WebRequest(string route, string token, Method method, string model)
{
    var client = new RestClient("myapiurl");
    var request = new RestRequest(route, method);

    //"model" is a json
    request.AddParameter("application/json", model, ParameterType.GetOrPost);
    request.AddHeader("Accept", "application/json");
    request.AddHeader("Authorization", "Bearer " + token);
    request.RequestFormat = DataFormat.Json;

    IRestResponse response = client.Execute(request);

    var content = response.Content;

    return true;
}

The request has 3 parameters:

{ application/json={ "CommunicationType":4854,"JobNumber":55555,"NotificationAddress":"(714) 978-9788","CreatedBy":"user@mail.com","IsDeleted":false } }
{ Accept=application/json }
{ Authorization=Bearer dasjd... }

But the response always returns:

StatusCode: UnsupportedMediaType

I didn't see anything wrong in my request, can someone see what is wrong?

Regards

Body:
Add need to add  content type in header

request.AddHeader("content-type", "application/json");

get reference GetOrPost:ParameterTypes for RestRequest

RequestBody If this parameter is set, its value will be sent as the
  body of the request. Only one RequestBody parameter is accepted - the
  first one.

The name of the parameter will be used as the Content-Type header for
  the request.

RequestBody does not work on GET or HEAD Requests, as they do not
  actually send a body.

If you have GetOrPost parameters as well, they will overwrite the
  RequestBody - RestSharp will not combine them but it will instead
  throw the RequestBody parameter away.

It is recommended to use AddJsonBody or AddXmlBody methods instead of
  AddParameter with type BodyParameter. Those methods will set the
  proper request type and do the serialization work for you.

I think you need to add

request.AddJsonBody(model); // AddJsonBody serializes the object automatically


问:
How to search and delete characters in string
I'm trying to convert .fsp files to strings but new .fsp file is very abnormal. It contains some undesirable characters that I want to delete from string. How can I make it?

I have tried to search char in string and delete them but I dont know how to make it.

The string looks like this:

string s;

```<code>s = 144˙037˙412˙864;
</code>```

and I need to make it just like that

```<code>s = 144037412864;
</code>```

So I except result like this:

```<code>string s = 144037412864;
</code>```

Thank you for help.

答:
We can use the remove-erase idiom to remove unnecessary characters from the string! There's a function in <algorithm> called remove_if. What remove_if does is it removes elements that match some predicate. remove_if returns a iterator pointing to the new end of the container after all elements have been removed. I'll show you how to write a function that does the job!

```<code>#include <algorithm>
#include <string>

void erase_ticks(std::string& s) {
    // Returns true for characters that should be removed
    auto condition = [](char c) { return c == '`'; };

    // Removes characters that match the condition,
    // and returns the new endpoint of the string
    auto new_end = std::remove_if(s.begin(), s.end(), condition);

    // Erases characters from the new endpoint to the current endpoint
    s.erase(new_end, s.end());
}
</code>```

We can use this in main, and it works just as expected!

```<code>#include <iostream>

int main() {
    std::string s("123`456`789");
    std::cout << s << '\n'; // prints 123`456`789
    erase_ticks(s);
    std::cout << s << '\n'; // prints 123456789
}
</code>```

Body:
I'm trying to convert .fsp files to strings but new .fsp file is very abnormal. It contains some undesirable characters that I want to delete from string. How can I make it?

I have tried to search char in string and delete them but I dont know how to make it.

The string looks like this:

string s;

s = 144˙037˙412˙864;

and I need to make it just like that

s = 144037412864;

So I except result like this:

string s = 144037412864;

Thank you for help.

Body:
We can use the remove-erase idiom to remove unnecessary characters from the string! There's a function in <algorithm> called remove_if. What remove_if does is it removes elements that match some predicate. remove_if returns a iterator pointing to the new end of the container after all elements have been removed. I'll show you how to write a function that does the job!

#include <algorithm>
#include <string>

void erase_ticks(std::string& s) {
    // Returns true for characters that should be removed
    auto condition = [](char c) { return c == '`'; };

    // Removes characters that match the condition,
    // and returns the new endpoint of the string
    auto new_end = std::remove_if(s.begin(), s.end(), condition);

    // Erases characters from the new endpoint to the current endpoint
    s.erase(new_end, s.end());
}

We can use this in main, and it works just as expected!

#include <iostream>

int main() {
    std::string s("123`456`789");
    std::cout << s << '\n'; // prints 123`456`789
    erase_ticks(s);
    std::cout << s << '\n'; // prints 123456789
}