简单的 Meteor + React + Iron Router CRUD 应用 [英] Simple Meteor + React + Iron Router CRUD application
问题描述
在过去的 2 天里,我一直在努力创建一个 Meteor + React + Iron Router 项目,该项目提供与这个基本的 PHP + HTML 页面完全相同的功能.
For the past 2 days, I've been struggling to create a Meteor + React + Iron Router project that offers the exact same functionality of this basic PHP + HTML page.
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
还显示当前项目.您可以编辑表单,或点击收藏列表中的链接以查看其他表单.
In other words, I want to look up a database for a collection of projects and also display the current project if the url is /project/:_id
. You can edit the form, or click on a link in the collection list to look at another form.
我已经阅读了 Meteor + React 待办事项列表教程,但我仍然在为基础知识而苦苦挣扎.我还是不知道如何将这个简单的PHP页面重新构建为meteor+react+iron router项目.谁能给我举个例子或帮我翻译一下?
I've gone through the Meteor + React To Do list tutorial, but I'm still struggling with the basics. I still don't know how to re-build this simple PHP page as a meteor + react + iron router project. Can anyone show me an example or translate this for me?
这个问题的答案可能会帮助我解决我之前问过的一个仍然悬而未决的问题:Meteor + React 如何设置很多输入元素的值并修改之后
An answer to this question will probably help me resolve a previous question I asked which is still outstanding: Meteor + React how to set the value of a lot of input elements and modify them after
推荐答案
我终于做到了.答案是这里问题中提供的代码的组合:
I finally did it. The answer is the combination of the code presented in this question here:
然后用接受的答案更新代码.
Then update the code with the accepted answer.
这篇关于简单的 Meteor + React + Iron Router CRUD 应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!