- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在将 xml 转换为 html 表,但在内部 for 循环中,尽管有 Row[i].cell.length
,但我收到 undefined
错误该单元格中的SPACER
查找演示 here
注意:您将收到的警报是该行的长度
最佳答案
当行节点内部有单个元素时,会引发错误。
我已经修改了将字符串元素转换为数组的代码,但在更正错误后出现了其他错误,我试图更正,但我认为应该对它们进行审查。
这是新代码
var myApp = angular.module('myApp', []);
myApp.controller("MyCtrl", function($scope) {
$scope.allText = '<Table rowSize="22"><Row cellSize="4"><Cell cellWidth="1500" realIndex="0" rowSpan="true">Cat. No. </Cell><Cell cellWidth="2795" realIndex="1">Suitable Copper Conductor Range </Cell><Cell cellWidth="3150" realIndex="2">Limiter Fuse </Cell><Cell cellWidth="1800" realIndex="3" rowSpan="true">SCCR, A </Cell></Row><Row cellSize="4"><Cell cellWidth="1500" realIndex="0" rowSpanIndex="0"></Cell><Cell cellWidth="1470" realIndex="1" columnSplitIndex="1">Line </Cell><Cell cellWidth="1325" realIndex="1" columnSplitIndex="1">Load </Cell><Cell cellWidth="1530" realIndex="2" columnSplitIndex="2">Ampere Max </Cell><Cell cellWidth="1620" realIndex="2" columnSplitIndex="2">Fuse Class </Cell><Cell cellWidth="1800" realIndex="3" rowSpanIndex="3"></Cell></Row><Row cellSize="4"><Cell cellWidth="1500" realIndex="0" rowSpan="true">DK35H </Cell><Cell cellWidth="1470" realIndex="1" rowSpan="true" columnSplitIndex="1">1/0 - 12 </Cell><Cell cellWidth="1325" realIndex="1" rowSpan="true" columnSplitIndex="1">1/0 - 12 </Cell><Cell cellWidth="1530" realIndex="2" columnSplitIndex="2">225 </Cell><Cell cellWidth="1620" realIndex="2" columnSplitIndex="2">J </Cell><Cell cellWidth="1800" realIndex="3" rowSpan="true">100,000 </Cell></Row><Row cellSize="4"><Cell cellWidth="1500" realIndex="0" rowSpanIndex="0"></Cell><Cell cellWidth="1470" realIndex="1" rowSpanIndex="1" columnSplitIndex="1"></Cell><Cell cellWidth="1325" realIndex="1" rowSpanIndex="2" columnSplitIndex="1"></Cell><Cell cellWidth="1530" realIndex="2" columnSplitIndex="2">225 </Cell><Cell cellWidth="1620" realIndex="2" columnSplitIndex="2">T </Cell><Cell cellWidth="1800" realIndex="3" rowSpanIndex="5"></Cell></Row><Row cellSize="4"><Cell cellWidth="1500" realIndex="0" rowSpanIndex="0"></Cell><Cell cellWidth="1470" realIndex="1" rowSpanIndex="1" columnSplitIndex="1"></Cell><Cell cellWidth="1325" realIndex="1" rowSpanIndex="2" columnSplitIndex="1"></Cell><Cell cellWidth="1530" realIndex="2" columnSplitIndex="2">100 </Cell><Cell cellWidth="1620" realIndex="2" columnSplitIndex="2">RK1 </Cell><Cell cellWidth="1800" realIndex="3" rowSpanIndex="5"></Cell></Row><Row cellSize="4"><Cell cellWidth="1500" realIndex="0" rowSpanIndex="0"></Cell><Cell cellWidth="1470" realIndex="1" rowSpanIndex="1" columnSplitIndex="1"></Cell><Cell cellWidth="1325" realIndex="1" rowSpanIndex="2" columnSplitIndex="1"></Cell><Cell cellWidth="1530" realIndex="2" columnSplitIndex="2">30 </Cell><Cell cellWidth="1620" realIndex="2" columnSplitIndex="2">RK5 </Cell><Cell cellWidth="1800" realIndex="3" rowSpanIndex="5"></Cell></Row><Row cellSize="4"><Cell cellWidth="1500" realIndex="0" rowSpanIndex="0"></Cell><Cell cellWidth="1470" realIndex="1" rowSpanIndex="1" columnSplitIndex="1"></Cell><Cell cellWidth="1325" realIndex="1" rowSpanIndex="2" columnSplitIndex="1"></Cell><Cell cellWidth="1530" realIndex="2" columnSplitIndex="2">60 </Cell><Cell cellWidth="1620" realIndex="2" columnSplitIndex="2">G </Cell><Cell cellWidth="1800" realIndex="3" rowSpanIndex="5"></Cell></Row><Row cellSize="4"><Cell cellWidth="1500" realIndex="0" rowSpanIndex="0"></Cell><Cell cellWidth="1470" realIndex="1" rowSpanIndex="1" columnSplitIndex="1"></Cell><Cell cellWidth="1325" realIndex="1" rowSpanIndex="2" columnSplitIndex="1"></Cell><Cell cellWidth="1530" realIndex="2" columnSplitIndex="2">30 </Cell><Cell cellWidth="1620" realIndex="2" columnSplitIndex="2">CC </Cell><Cell cellWidth="1800" realIndex="3" rowSpanIndex="5"></Cell></Row><Row cellSize="1"><Cell cellWidth="9245" realIndex="0" colSpanSize="4"> SPACER </Cell></Row><Row cellSize="4"><Cell cellWidth="1500" realIndex="0" rowSpan="true">DKK4-TF (5X20) UPPER </Cell><Cell cellWidth="1470" realIndex="1" rowSpan="true" columnSplitIndex="1">10 - 18 </Cell><Cell cellWidth="1325" realIndex="1" rowSpan="true" columnSplitIndex="1">10 18 </Cell><Cell cellWidth="1530" realIndex="2" columnSplitIndex="2">60 </Cell><Cell cellWidth="1620" realIndex="2" columnSplitIndex="2">J </Cell><Cell cellWidth="1800" realIndex="3" rowSpan="true">100,000 </Cell></Row><Row cellSize="4"><Cell cellWidth="1500" realIndex="0" rowSpanIndex="0"></Cell><Cell cellWidth="1470" realIndex="1" rowSpanIndex="1" columnSplitIndex="1"></Cell><Cell cellWidth="1325" realIndex="1" rowSpanIndex="2" columnSplitIndex="1"></Cell><Cell cellWidth="1530" realIndex="2" columnSplitIndex="2">60 </Cell><Cell cellWidth="1620" realIndex="2" columnSplitIndex="2">T </Cell><Cell cellWidth="1800" realIndex="3" rowSpanIndex="5"></Cell></Row><Row cellSize="4"><Cell cellWidth="1500" realIndex="0" rowSpanIndex="0"></Cell><Cell cellWidth="1470" realIndex="1" rowSpanIndex="1" columnSplitIndex="1"></Cell><Cell cellWidth="1325" realIndex="1" rowSpanIndex="2" columnSplitIndex="1"></Cell><Cell cellWidth="1530" realIndex="2" columnSplitIndex="2">30 </Cell><Cell cellWidth="1620" realIndex="2" columnSplitIndex="2">RK1 </Cell><Cell cellWidth="1800" realIndex="3" rowSpanIndex="5"></Cell></Row><Row cellSize="4"><Cell cellWidth="1500" realIndex="0" rowSpanIndex="0"></Cell><Cell cellWidth="1470" realIndex="1" rowSpanIndex="1" columnSplitIndex="1"></Cell><Cell cellWidth="1325" realIndex="1" rowSpanIndex="2" columnSplitIndex="1"></Cell><Cell cellWidth="1530" realIndex="2" columnSplitIndex="2">- </Cell><Cell cellWidth="1620" realIndex="2" columnSplitIndex="2">RK5 </Cell><Cell cellWidth="1800" realIndex="3" rowSpanIndex="5"></Cell></Row><Row cellSize="4"><Cell cellWidth="1500" realIndex="0" rowSpanIndex="0"></Cell><Cell cellWidth="1470" realIndex="1" rowSpanIndex="1" columnSplitIndex="1"></Cell><Cell cellWidth="1325" realIndex="1" rowSpanIndex="2" columnSplitIndex="1"></Cell><Cell cellWidth="1530" realIndex="2" columnSplitIndex="2">50 </Cell><Cell cellWidth="1620" realIndex="2" columnSplitIndex="2">G </Cell><Cell cellWidth="1800" realIndex="3" rowSpanIndex="5"></Cell></Row><Row cellSize="4"><Cell cellWidth="1500" realIndex="0" rowSpanIndex="0"></Cell><Cell cellWidth="1470" realIndex="1" rowSpanIndex="1" columnSplitIndex="1"></Cell><Cell cellWidth="1325" realIndex="1" rowSpanIndex="2" columnSplitIndex="1"></Cell><Cell cellWidth="1530" realIndex="2" columnSplitIndex="2">30 </Cell><Cell cellWidth="1620" realIndex="2" columnSplitIndex="2">CC </Cell><Cell cellWidth="1800" realIndex="3" rowSpanIndex="5"></Cell></Row><Row cellSize="1"><Cell cellWidth="9245" realIndex="0" colSpanSize="4"> SPACER </Cell></Row><Row cellSize="4"><Cell cellWidth="1500" realIndex="0" rowSpan="true">DKK4-TF (5X20) LOWER </Cell><Cell cellWidth="1470" realIndex="1" rowSpan="true" columnSplitIndex="1">10 18 </Cell><Cell cellWidth="1325" realIndex="1" rowSpan="true" columnSplitIndex="1">10 18 </Cell><Cell cellWidth="1530" realIndex="2" columnSplitIndex="2">60 </Cell><Cell cellWidth="1620" realIndex="2" columnSplitIndex="2">J </Cell><Cell cellWidth="1800" realIndex="3" rowSpan="true">100,000 </Cell></Row><Row cellSize="4"><Cell cellWidth="1500" realIndex="0" rowSpanIndex="0"></Cell><Cell cellWidth="1470" realIndex="1" rowSpanIndex="1" columnSplitIndex="1"></Cell><Cell cellWidth="1325" realIndex="1" rowSpanIndex="2" columnSplitIndex="1"></Cell><Cell cellWidth="1530" realIndex="2" columnSplitIndex="2">60 </Cell><Cell cellWidth="1620" realIndex="2" columnSplitIndex="2">T </Cell><Cell cellWidth="1800" realIndex="3" rowSpanIndex="5"></Cell></Row><Row cellSize="4"><Cell cellWidth="1500" realIndex="0" rowSpanIndex="0"></Cell><Cell cellWidth="1470" realIndex="1" rowSpanIndex="1" columnSplitIndex="1"></Cell><Cell cellWidth="1325" realIndex="1" rowSpanIndex="2" columnSplitIndex="1"></Cell><Cell cellWidth="1530" realIndex="2" columnSplitIndex="2">30 </Cell><Cell cellWidth="1620" realIndex="2" columnSplitIndex="2">RK1 </Cell><Cell cellWidth="1800" realIndex="3" rowSpanIndex="5"></Cell></Row><Row cellSize="4"><Cell cellWidth="1500" realIndex="0" rowSpanIndex="0"></Cell><Cell cellWidth="1470" realIndex="1" rowSpanIndex="1" columnSplitIndex="1"></Cell><Cell cellWidth="1325" realIndex="1" rowSpanIndex="2" columnSplitIndex="1"></Cell><Cell cellWidth="1530" realIndex="2" columnSplitIndex="2">- </Cell><Cell cellWidth="1620" realIndex="2" columnSplitIndex="2">RK5 </Cell><Cell cellWidth="1800" realIndex="3" rowSpanIndex="5"></Cell></Row><Row cellSize="4"><Cell cellWidth="1500" realIndex="0" rowSpanIndex="0"></Cell><Cell cellWidth="1470" realIndex="1" rowSpanIndex="1" columnSplitIndex="1"></Cell><Cell cellWidth="1325" realIndex="1" rowSpanIndex="2" columnSplitIndex="1"></Cell><Cell cellWidth="1530" realIndex="2" columnSplitIndex="2">50 </Cell><Cell cellWidth="1620" realIndex="2" columnSplitIndex="2">G </Cell><Cell cellWidth="1800" realIndex="3" rowSpanIndex="5"></Cell></Row><Row cellSize="4"><Cell cellWidth="1500" realIndex="0" rowSpanIndex="0"></Cell><Cell cellWidth="1470" realIndex="1" rowSpanIndex="1" columnSplitIndex="1"></Cell><Cell cellWidth="1325" realIndex="1" rowSpanIndex="2" columnSplitIndex="1"></Cell><Cell cellWidth="1530" realIndex="2" columnSplitIndex="2">30 </Cell><Cell cellWidth="1620" realIndex="2" columnSplitIndex="2">CC </Cell><Cell cellWidth="1800" realIndex="3" rowSpanIndex="5"></Cell></Row></Table>';
$scope.processData = function(allText) {
var xmlText = allText.replace(/\n/, '')
var x2js = new X2JS();
var json = x2js.xml_str2json(xmlText);
var str = JSON.stringify(json);
$scope.json = str;
$scope.data = json.Table.Row;
for (var i = 0; i < json.Table.Row.length; i++) {
//var cells = json.Table.Row[i].Cell.length;
var header = 0;
// Transform the object into array
if (json.Table.Row[i].Cell.constructor !== Array) {
var asArray = [];
asArray.push(json.Table.Row[i].Cell);
json.Table.Row[i].Cell = asArray;
}
//alert( json.Table.Row[i].Cell.length)
for (var j = 0; j < json.Table.Row[i].Cell.length; j++) {
//alert(json.Table.Row[i].Cell[j].__text);
//Row Span initialization
if (json.Table.Row[i].Cell[j]._rowSpan) {
json.Table.Row[i].Cell[j]['rSpan'] = '1';
}
//Column Span
if (json.Table.Row[i].Cell[j]._colSpanSize != null) {
var limit = json.Table.Row[i].Cell[j]._colSpanSize;
var count = 0;
while (limit > 0) {
if (json.Table.Row[0].Cell[header].cSpan != null) {
count += json.Table.Row[0].Cell[header].cSpan;
} else {
count++;
}
header++;
limit--;
}
json.Table.Row[i].Cell[j]['cSpan'] = count;
}
//Row Span
if (json.Table.Row[i].Cell[j]._rowSpanIndex != null) {
var col = json.Table.Row[i].Cell[j]._rowSpanIndex;
var row = i;
while (!json.Table.Row[row].Cell[col]._rowSpan) {
row--;
}
json.Table.Row[row].Cell[col].rSpan++;
}
//Column Split
if (json.Table.Row[i].Cell[j]._columnSplitIndex != null) {
var count = 1,
col = j,
k = 0;
var index = json.Table.Row[i].Cell[j]._columnSplitIndex;
if (json.Table.Row[i - 1].Cell[k] == null) {
continue;
}
// here check for undefined
while (
json.Table.Row[i - 1].Cell[k] &&
json.Table.Row[i - 1].Cell[k]._realIndex != index) {
k++;
}
// here check for undefined
if (json.Table.Row[i - 1].Cell[k] &&
json.Table.Row[i - 1].Cell[k]._columnSplitIndex != null) {
continue;
}
if (json.Table.Row[0].Cell[index].cSpan != null) {
continue;
}
while (json.Table.Row[i].Cell[col]._columnSplitIndex == json.Table.Row[i].Cell[col + 1]._columnSplitIndex) {
count++;
col++;
}
json.Table.Row[i - 1].Cell[k]['cSpan'] = count;
}
}
}
$scope.data = json.Table.Row;
if (!$scope.$$phase) $scope.$apply();
}
});
关于javascript - array.length AngularJS 的未定义错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34526898/
我找到了以下代码片段: length = length and length or len(string) 在我看来,这应该等同于: length = length or len(string) 我能
当我使用 numpy.shape() 检查数组的形状时,我有时会得到 (length,1) 有时会得到 (length,)。看起来区别在于列向量与行向量......但它似乎并没有改变数组本身的任何内容
我正在学习 Java,有一个简单的问题。 在设置类的示例中,我看到了这一点: length >= 0 ? length : length * -1 这是什么意思? 谢谢。 最佳答案 这是一种骇人听闻的
我在阅读有关在 Ruby 中重新定义方法有多么容易的文章时遇到了以下问题: class Array alias :old_length :length def length old_l
例如在下面的代码中a和b和c是相等的。 EditText editText; editText = (EditText) findViewById(R.id.edttxt); editText.set
在昨天教授我的 JavaScript 类(class)时,我和我的学生遇到了一些有趣的功能,我认为这些功能可能值得在一个问题和我得出的答案中捕捉到。 在 Chrome 的 JS 控制台中输入 Arra
这个问题在这里已经有了答案: How can I get the size of an array, a Collection, or a String in Java? (3 个回答) 3年前关闭。
这个问题在这里已经有了答案: length and length() in Java (8 个答案) 关闭 6 年前。 我注意到在计算数组的长度时,你会这样写: arrayone.length; 但
console.log(this.slides.length()); 打印 Cannot read property 'length' of undefined.在 setTimeout 为 100
在搜索stackoverflow问题时,我发现了此链接: Error in file.download when downloading custom file。 但是,我的情况有些不同(我认为):
这个问题已经有答案了: Why does R use partial matching? (1 个回答) 已关闭 8 年前。 大家。我刚刚开始使用 swirl 学习 R 编程。 我刚刚了解到seq 。
这个问题已经有答案了: Why does R use partial matching? (1 个回答) 已关闭 8 年前。 大家。我刚刚开始使用 swirl 学习 R 编程。 我刚刚了解到seq 。
这个问题已经有答案了: How can I get the size of an array, a Collection, or a String in Java? (3 个回答) 已关闭 9 年前。
我有一个大数组,其中包含所有类型( bool 值,数组,null,...),并且我正在尝试访问它们的属性arr[i].length,但有些其中显然没有长度。 我不介意那些缺少长度的人是否返回未定义(我
我在对象的属性中有一些文本。我正在测试对象的属性中是否有要显示的文本;如果没有,那么我显示“-”而不是空白。看起来没有什么区别: if (MyObject.SomeText && MyObject.S
这个问题在这里已经有了答案: 关闭 10 年前。 Possible Duplicate: Why is String.length() a method? Java - Array's length
这个问题在这里已经有了答案: obj.length === +obj.length in javascript (4 个答案) 关闭 9 年前。 我一直在读underscore.js源代码并在 _.
#include using std::cout; using std::cin; using std::string; int main(){ cout > name; cout
我正在细读 underscore.js annotated source当我遇到这个时: if (obj.length === +obj.length) {...} 我现在从this stackove
我正在查看 dotnet 运行时中的一些代码,我注意到不是这样写的: if (args.Length > 0) 他们使用这个: if (args is { Length: > 0}) 你知道用第二种方
我是一名优秀的程序员,十分优秀!