我对ngHandsontable有疑问组件:我收到此错误:
Cannot set property 'datarows' of undefined
尝试初始化表时。我正在使用的代码是这样的:
<hot-table rowHeaders="true" startRows= "7" manualColumnResize="true" datarows="td"
settings="{ colWidths: [150, 150, 150, 150,150], colHeaders: colHeaders, contextMenu: ['row_above', 'row_below', 'remove_row'], afterChange: afterChange }">
<hot-column data="COLUMN_1" title="'COLUMN_1'"></hot-column>
<hot-column data="COLUMN_2" title="'COLUMN_2'"></hot-column>
<hot-column data="COLUMN_3" title="'COLUMN_3'"></hot-column>
<hot-column data="COLUMN_4" title="'COLUMN_4'"></hot-column>
<hot-column data="COLUMN_5" title="'COLUMN_5'"></hot-column>
</hot-table>
在 Controller 中:
$scope.td = [{
'COLUMN_1': ''
}];
请注意,settings
对象具有一些我的 Controller 中不存在的默认属性(colHeaders
和 afterChange
)。我几乎尝试了一切:我删除了设置属性、数据行属性、所有属性!错误消息没有任何变化。
查看 ngHandsontable 的源代码,我发现这是有问题的行:
angular.forEach(bindingsKeys, function(key) {
var mode = _this.scope[key].charAt(0);
_this.$$isolateBindings[key] = {
attrName: _this.scope[key].length > 1 ? _this.scope[key].substr(1, _this.scope[key].length) : key,
collection: key === 'datarows',
mode: mode,
optional: false
};
});
错误在于 _this.$$isolateBindings[key]
未定义 _this.$$isolateBindings
。
我对此一无所知,我发现我的案例中的配置与指令的示例略有不同。
我实际上使用的是 0.9.0 版本,以及 Handsontable 0.23.0(免费)和 AngularJS 1.2.28。
我在这里缺少什么?
谢谢。
最佳答案
我刚刚发现这个:
https://github.com/handsontable/ngHandsontable/blob/develop/index.html#L69
Note: ngHandsontable supports angular in version 1.3 and greater.
这是因为您使用的是较旧的 Angular 版本。我刚刚升级到 Angular 1.5.8,然后它就可以工作了。
关于javascript - 无法在 ngHandsontable 中设置未定义的属性 'datarows',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37798221/