2017-01-10 42 views
0

我開始在Reactjs Griddle Grid上工作,在實現代碼時出現錯誤,我在想這是基本錯誤,但我能夠解決。錯誤是「ReferenceError:fakeData is沒有定義「。請幫助我reslove。Reactjs Griddle Grid

我的代碼是:

export default class Products extends Component { 
debugger; 
    constructor(props) { 
    super(props); 

    this.state = { }; 
    this.state.filterText = ""; 
    this.fakeData = [ 
    { 
    "id": 0, 
    "name": "Mayer Leonard", 
    "city": "Kapowsin", 
    "state": "Hawaii", 
    "country": "United Kingdom", 
    "company": "Ovolo", 
    "favoriteNumber": 7 
    }, 

]; 
    } 

    render() { 

    return (
<Griddle results={fakeData} tableClassName="table" showFilter={true} 
showSettings={true} columns={["name", "city", "state", "country"]}/> 
    ); 

    } 

} 

回答

0

只需添加this.fakeData應該工作

<Griddle results={this.fakeData} tableClassName="table" showFilter={true} 
showSettings={true} columns={["name", "city", "state", "country"]}/> 
+0

感謝它的工作 –

+0

我需要放置一個按鈕的Griddle的頂部是可能的嗎? –

+0

爲什麼使用你需要的頂部按鈕?平板電腦文件提供了您可以自定義平板電腦的方法,您可以更具體 – LINOJ

0

我看你從Griddle Documentation和無級他們的榜樣了示例代碼。所以他們稱這個變量。

在你的例子中,它是一個類成員數據。

export default class Products extends Component { 
    constructor(props) { 
     super(props); 

     this.state = {}; 
     this.state.filterText = ""; 
     this.fakeData = [{ 
       "id": 0, 
       "name": "Mayer Leonard", 
       "city": "Kapowsin", 
       "state": "Hawaii", 
       "country": "United Kingdom", 
       "company": "Ovolo", 
       "favoriteNumber": 7 
      }, 

     ]; 
    } 

    render() { 

     return (<Griddle results = {this.fakeData} 
      tableClassName = "table" 
      showFilter = { 
       true 
      } 
      showSettings = { 
       true 
      } 
      columns = { 
       ["name", "city", "state", "country"] 
      } 
      /> 
     ); 

    } 

} 

我建議你去了解ES6 BasicsGriddle examples