[英]Parse.com retrieve createdAt field Javascript
I'm having trouble retrieving the createdAt field in javascript/html using parse. 我在使用解析获取javascript / html中的createdAt字段时遇到问题。 Here's how I'm displaying my current fields in HTML.
这是我在HTML中显示当前字段的方式。 For reference, the original tutorial I got this from is here: http://code.tutsplus.com/tutorials/getting-started-with-parse--net-28000
作为参考,我从这里获得的原始教程位于: http : //code.tutsplus.com/tutorials/getting-started-with-parse--net-28000
<script id="todo-items-template" type="x/handlebars">
<table id="data">
<tr><td class="first">Rank</td>
<td class="second"> <li class="list-item"><input type="checkbox" id="{id}">{content}</li></td>
<td class="third" ><li class="list-item"><output type="date" id="{id}">{createdAt}</li></td>
</tr>
</table>
</script>
And here is how I'm saving it in the javascript. 这就是我将其保存在javascript中的方法。 When the webpage displays, the content is correct, but the createdAt field just shows {createdAt}.
显示网页时,内容正确,但是createdAt字段仅显示{createdAt}。 As you can see below, I attempted to retrieve it directly after I saved it, but no luck.
正如您在下面看到的那样,我尝试在保存后直接检索它,但是没有运气。 I've also tried putting it into the query as well, also with no luck.
我也尝试过将其放入查询中,也没有运气。 I feel like I might be trying to display it incorrectly.
我觉得我可能试图显示不正确。
//Handle Click Event
submitBtn.on('click', function(e) {
//Save the current Todo
var text = Y.one('#list-input').get('value');
var ListItem = Parse.Object.extend("ListItem");
var listItem = new ListItem();
listItem.set("content", text);
listItem.set("isComplete", false);
//Once it is saved, show it in the list of todo's.
listItem.save(null, {
success: function(item) {
noTasksMessage.addClass('hidden');
var content = Y.Lang.sub(Y.one('#todo-items-template').getHTML(), {
content: item.get('content'),
id: item.id,
});
incompleteItemList.append(content);
input.set('value', '').focus();
},
error: function(gameScore, error) {
alert("Error when saving Todos: " + error.code + " " + error.message);
}
});
var createdAt = listItem.createdAt;
});
And finally, here is how I'm retrieving my parse objects: 最后,这是我检索解析对象的方式:
//Get 10 most recent incomplete Todos.
ListItem = Parse.Object.extend("ListItem");
query = new Parse.Query(ListItem);
query.equalTo('isComplete', false)
query.limit = 10;
query.descending('createdAt');
query.find({
success: function(results) {
if (results.length > 0) {
noTasksMessage.addClass('hidden');
}
//Append each of the incomplete tasks to the Incomplete List
Y.Array.each(results, function(val, i, arr) {
var content = Y.Lang.sub(Y.one('#todo-items-template').getHTML(), {
content: val.get('content'),
id: val.id,
isComplete: false
});
incompleteItemList.append(content);
});
//When the checkbox is clicked for any of the items in the incomplete list, update it as complete.
incompleteItemList.delegate('click', function (e) {
var self = this;
query = new Parse.Query(ListItem);
query.get(self.one('input').get('id'), {
success: function(item) {
item.set('isComplete', true);
item.save();
self.remove();
if (incompleteItemList.all('li').size() >= 1) {
noTasksMessage.removeClass('hidden');
}
},
error: function(object, error) {
alert("Error when updating todo item: " + error.code + " " + error.message);
}
});
}, 'li');
},
error: function(error) {
alert("Error when retrieving Todos: " + error.code + " " + error.message);
}
});
Solved it.. was easier than I thought. 解决了..比我想象的容易。
First, in your html do: 首先,在您的html中执行以下操作:
<td class="third">{created}</td>
Second, when saving it: created: 二,保存时:创建:
item.getDate('createdAt')
Finally, when querying: 最后,在查询时:
created: val.createdAt
Voila! 瞧!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.