我想创建一个随机表数据,但只有单元格随机排列总是重复的行。这是我的代码:
组件/余烬-app..js
import Ember from 'ember';
export default Ember.Component.extend({
willRender: function() {
var tableRows = [];
var value = ['|', '-'];
var numRows = 20;
var numCells = 20;
for (var row = 1; row <= numRows; row++) {
for (var cell = 1; cell <= numCells; cell++) {
tableRows[row] = value[Math.round(Math.random())];
}
}
this.set('rows', {
'tableRows': tableRows,
});
}
});
和templates / components / ember-app.hbs
<table>
{{#each-in rows as |table tableRow|}}
{{#each tableRow}}
<tr>
{{#each tableRow as |tableRows|}}
<td><button id="button_id"{{action "changeValue"}} value="{{tableRows}}">{{tableRows}}</button></td>
{{/each}}
</tr>
{{/each}}
{{/each-in}}
</table>
答案 0 :(得分:0)
您没有为每一行创建不同的单元格值
Component.js
<table>
{{#each-in rows as |table tableRow|}}
{{log 'tableRow ' tableRow ' table ' table}}
{{#each tableRow as |singleRow|}}
<tr>
{{#each singleRow as |tableRows|}}
<td><button id="button_id"{{action "changeValue"}} value="{{tableRows}}">{{tableRows}}</button></td>
{{/each}}
</tr>
{{/each}}
{{/each-in}}
</table>
{{yield}}
在组件hbs中,
Ember.Object
我建议你考虑init
并使用init hook来gci c:\temp\backup\*.bak | ren -N { $_ -replace 'backup_\d+_\d+_\d+_' } -whatif
# get matching files and | rename them with new names
# replacement pattern is 'backup' followed by strings of digits and underscores, replaced with nothing.
数据。
ember-twiddle