var SomeObject = xmlDoc2.get('Objects').childNodes();
SomeObject.forEach(function (child) {
var theId = child.attr('id');
if (theId !== null) {
var theIdVal = theId.value();
console.log('Id: ' + theIdVal);
app.get('/obj/:id', function (req, res) {
if (req.params.id == theIdVal) {
res.json('This is id: ' + theIdVal);
console.log('This is id: ' + theIdVal)
}
else {
}
})
}
});
问题是我只能获得/ obj / first - >第一个元素的id url。 如果我键入“两个”,它只是继续加载页面,没有结果。 (并且假设xml看起来像这样:)
<Objects>
<Object id="First">
</Object>
<Object id="Two">
</Object>
<Object id="Three">
</Object>
</Objects>