简单的Meteor+React+Iron Router CRUD应用程序


Simple Meteor + React + Iron Router CRUD application

在过去的两天里,我一直在努力创建一个Meteor+Rreact+Iron Router项目,该项目提供与这个基本的PHP+HTML页面完全相同的功能。

index.php

<?php
include('library.php');
// CREATE or UPDATE
if($_POST['save'] && $_POST['_id'])
    $db('tblProject')->update($_POST);
else if($_POST['save'])
    $db('tblProject')->insert($_POST);
// READ
$arrProject = $db('tblProject')->collection->find();
$arrCurrentProject = $db('tblProject')>collection->findOne(array('_id'=>$_GET['_id']));
$htmlForm = new DOMDocument();
$htmlForm->loadHTMLFile('form.html');
$input = $htmlForm->getElementsByTagName('input');
foreach ($input as $i) {
        $i->setAttribute('value',$arrCurrentProject[$i->getAttribute('name')]);
}
$textarea = $htmlForm->getElementsByTagName('textarea');
foreach ($textarea as $i) {
        $i->nodeValue = $arrCurrentProject[$i->getAttribute('name')];
}
?><!DOCTYPE html>
<html>
<head>
</head>
<body>
  <ul>
    <?php foreach($arrProject as $row) : ?>
        <li><a href="<?php echo 'http://'.$_SERVER['SERVER_NAME'].'/project/'.$row['_id']; ?>">Project <?php echo $row['_id']; ?></a></li>
    <?php endforeach; ?>
  </ul>
  <?php echo $htmlForm->saveHTML(); ?>
</body>
</html>

form.html

  <form method="post">
     <span>Hello this is some text</span>
     <input type="text" name="input1"/>
     <p>Blah blah this is boring</p>
     <input type="text" name="input2"/>
     <img src="image-of-a-kangaroo.png" />
     <input type="text" name="input3" />
     <ul>
        <li>Buy brocolli</li>
        <li>Buy oregano</li>
     </ul>
     <input type="text" name="input4" />
     <textarea name="input100"></textarea>
     <input type="text" name="input101" />
     <p><strong>Yes, I like pizza!</strong><span>But my porcupine gets sick eating pizza.</span></p>
     <button type="submit" value="save">Save</button>
  </form>

换句话说,如果url是/project/:_id,我想查找一个项目集合的数据库,并显示当前项目。您可以编辑表单,或者单击集合列表中的链接查看另一个表单。

我已经完成了Meteor+React To Do列表教程,但我仍在努力学习基础知识。我仍然不知道如何将这个简单的PHP页面重新构建为流星+反应+铁路由器项目。有人能给我举个例子或帮我翻译一下吗?

这个问题的答案可能会帮助我解决我之前提出的一个仍然悬而未决的问题:Meteor+React如何设置许多输入元素的值,并在后对其进行修改

我终于做到了。答案是这个问题中给出的代码的组合:

在现有状态转换期间无法更新

然后用接受的答案更新代码。