【问题标题】:Simple Meteor + React + Iron Router CRUD application简单的 Meteor + React + Iron Router CRUD 应用程序
【发布时间】:2016-03-31 07:31:50
【问题描述】:

在过去的 2 天里,我一直在努力创建一个 Meteor + React + 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 list 教程,但我仍在努力学习基础知识。我仍然不知道如何将这个简单的 PHP 页面重新构建为流星 + 反应 + 铁路由器项目。谁能给我看一个例子或者帮我翻译一下?

对这个问题的回答可能会帮助我解决我之前提出的一个仍然悬而未决的问题: Meteor + React how to set the value of a lot of input elements and modify them after

【问题讨论】:

    标签: php meteor reactjs


    【解决方案1】:

    我终于做到了。答案是这里问题中提供的代码的组合:

    Cannot update during an existing state transition

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

    【讨论】:

      猜你喜欢
      • 2017-06-17
      • 2015-06-05
      • 2015-02-23
      • 1970-01-01
      • 2014-05-07
      • 2013-11-21
      • 1970-01-01
      • 2023-03-12
      • 1970-01-01
      相关资源
      最近更新 更多