当我想在简单的表数据参数()上使用bind助手时。若要更改该列的颜色,它将在控制台上写入一个错误:
TypeError:无法读取未定义的属性“getAttribute”
-Here是我的index.hbs:
<table id="t01">
<tr>
<th>Company Name</th>
<th>Headquarters</th>
<th>revenue</th>
</tr>
{{#each model as |index|}}
<tr>
<td> {{index.name}} </td>
<td {{bind-attr class="className"}}> {{index.headquarters}} </td>
<td> {{index.revenue}} </td>
</tr>
{{/each}}
</table>
<button {{action "toggleColor"}}> Change color </button>
-And这里是我的index.js控制器:
import Ember from 'ember';
export default Ember.Controller.extend({
className:"red",
actions:{
toggleColor: function(){
if(this.get("className") == "red"){
this.set("className","blue");
}else{
this.set("className","red");
}
}
}
});
-Does有人知道怎么回事吗?它甚至没有显示表中的值,如果我不使用bind,则会实际显示这些值。
更新:
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return [{
"name" : "Google",
"headquarters": "Mountain View, California, United States of America",
"revenue":"59825000000"
},{
"name" : "Facebook",
"headquarters":"Menlo Park, California,United States of America",
"revenue":"7870000000"
},{
"name" : "twitter",
"revenue": "664000000",
"headquarters":"San Francisco, California, United States of America"
}];
}
});
发布于 2017-07-01 07:05:02
您也可以直接将属性分配给class
属性。您不需要使用bind-attr
。
对于<td class={{classNameProperty}}>
,如果classNameProperty
是red
,那么您将得到<td class="red">
。
对于<td calss={{if isActive 'form-control active' 'form-control'}}
,
如果isActive
是真值,那么您将得到<td class="form-control active">
,如果它是假的,那么您将得到<td class="form-control">
。
请参阅:
https://stackoverflow.com/questions/44856284
复制相似问题