Javascript “反应”;遇到了一个无效的子项“;错误
我使用react来呈现一个类似于电子表格的表。每个单元格都有一个输入字段,您可以在整行中填充每个单元格。但是,我只希望始终有一行输入为空。我正在使用以下代码渲染Javascript “反应”;遇到了一个无效的子项“;错误,javascript,reactjs,Javascript,Reactjs,我使用react来呈现一个类似于电子表格的表。每个单元格都有一个输入字段,您可以在整行中填充每个单元格。但是,我只希望始终有一行输入为空。我正在使用以下代码渲染 我的逻辑是,一旦您开始在一个新行中填写输入,它就会将其保存在state.new_行中,并在其下方呈现另一个空行。但是,它会停止渲染,并显示以下错误: [Warning] Child objects should have non-numeric keys so ordering is preserved. Check the rende
我的逻辑是,一旦您开始在一个新行中填写输入,它就会将其保存在state.new_行中,并在其下方呈现另一个空行。但是,它会停止渲染,并显示以下错误:
[Warning] Child objects should have non-numeric keys so ordering is preserved. Check the render method of LineItemList. See http://fb.me/react-warning-keys for more information. (851543_741761425909553_1789649762_n.js, line 9663)
[Error] Error: Invariant Violation: traverseAllChildren(...): Encountered an invalid child; DOM elements are not valid children of React components.
perform (851543_741761425909553_1789649762_n.js, line 15428)
batchedUpdates (851543_741761425909553_1789649762_n.js, line 8681)
enqueueUpdate (851543_741761425909553_1789649762_n.js, line 13744)
replaceState (851543_741761425909553_1789649762_n.js, line 6211)
setState (851543_741761425909553_1789649762_n.js, line 6183)
ensureNewRow (table_body.js, line 17)
(anonymous function) ([native code], line 0)
dispatch (jquery.js, line 4642)
handle (jquery.js, line 4310)
下面的链接实际上把我带到了这里:“它说用字符串作为键的前缀(我已经这样做了——我尝试用相同的前缀作为它们的前缀,并尝试使用不同的前缀)
对不起,代码不太漂亮,我已经在这个问题上纠缠了好几天了!如果有人至少能给我指出正确的方向,或者让我知道问题的原因,那将是非常有帮助的!或者,如果我违反了某些React原则,请告诉我它是什么,以便我可以修复它(这毕竟是我第一次使用React)问题来自意外地将查询对象保存到状态。这导致变量在映射函数中翻转,将键设置为[object object],并将
保留为只渲染给定的整数。我刚刚在新行
分配链的末尾调用了.toArray()
var new_rows = $(this.getDOMNode())
.find('[data-unsaved][data-has-changed]')
.map(function(i, el) { return $(el).find('input') })
.map(function(i, inputs) {
return _.reduce(inputs, function(memo, input) {
var $input = $(input)
, attrName = $input.attr('name').match(/\[([^\[]*)\]$/)[1]
memo[attrName] = $input.val()
return memo
}, {})
})
this.setState({ // This is line 17, in the function ensureNewRow, of table_body.js
existing_rows: this.state.existing_rows
, new_rows: new_rows
})
[Warning] Child objects should have non-numeric keys so ordering is preserved. Check the render method of LineItemList. See http://fb.me/react-warning-keys for more information. (851543_741761425909553_1789649762_n.js, line 9663)
[Error] Error: Invariant Violation: traverseAllChildren(...): Encountered an invalid child; DOM elements are not valid children of React components.
perform (851543_741761425909553_1789649762_n.js, line 15428)
batchedUpdates (851543_741761425909553_1789649762_n.js, line 8681)
enqueueUpdate (851543_741761425909553_1789649762_n.js, line 13744)
replaceState (851543_741761425909553_1789649762_n.js, line 6211)
setState (851543_741761425909553_1789649762_n.js, line 6183)
ensureNewRow (table_body.js, line 17)
(anonymous function) ([native code], line 0)
dispatch (jquery.js, line 4642)
handle (jquery.js, line 4310)