我刚刚探索了meteor.js并进行了一些实验..我想使用文本框更新数据..但是文本框是从模板帮助程序迭代生成的。如何使用包含迭代的模板帮助来更新流星中的流星数据
所以,场景就像我们输入数据,然后再retrive它,我们可以修改我们的数据。所以,当我们编辑
问题是我无法从文本框中获取值..其始终“undefined”..这里是我的html代码:
<body>
<form class="InsertTEST">
<input type="text" name="att1" placeholder="fill the att1"/>
<input type="text" name="att2" placeholder="fill the att3"/>
<input type="submit" value="submit"/>
</form>
<table>
{{#each a}}
{{> test}}
{{/each}}
</table>
</body>
<template name="test">
<tr class="testRow">
<td><input type="checkbox" class="toogle-check"></td>
<td><input type="text" id="att4" value="{{att1}}"/></td>
<td><input type="text" id="att5" value="{{att2}}"/></td>
<td><a href="#">{{att3}}</a></td>
<td><button class="UpdateTEST">Update</button></td>
<td><button class="DeleteTEST">Remove</button></td>
</tr>
</template>
这里我的js代码:
TEST = new Mongo.Collection('TEST');
if (Meteor.isClient) {
Template.body.helpers({
a: function() {
return TEST.find();
}
});
Template.body.events({
'submit .InsertTEST' : function(event){
var _att1 = event.target.att1.value;
var _att3 = new Date();
var _att2 = Number(event.target.att2.value) + 10;
Meteor.call('InsertTEST', _att1, _att2, _att3);
event.target.att1.value = "";
event.target.att2.value = "";
return false;
}
});
Template.test.events({
'click .UpdateTEST' : function(e,t) {
var _att4 = $('#att4').val();
alert(_att4);
/*
var query = {
att1 : _att4,
att2 : _att5
};
*/
TEST.update(this._id, {$set:query});
return false;
}
});
}
if (Meteor.isServer) {
Meteor.methods({
'InsertTEST' : function(_att1, _att2, _att3) {
TEST.insert({
att1:_att1, att2:_att2
});
}
});
}
嗨Billybobbonnet,感谢你的答案..我会接受你的建议对适当的名称和标签体:d ..关于渲染的东西,我会先尝试它..谢谢 –