我正在尝试创建指向其他页面的链接,以便您可以在查询搜索后单独查看一个配方。在查询找到所有结果后,无法找到如何执行此操作。我想要它,所以当你点击食谱的标题时,它会将你引导到另一个页面,并将其与该食谱的特定数据一起呈现。
Parse.initialize("ID","JSID");
var Recipes = Parse.Object.extend("Recipes");
var recipesQuery = new Parse.Query(Recipes);
recipesQuery.exists("Images");
recipesQuery.equalTo("feeds", "4");
recipesQuery.find({
success: function(results) {
//Return values of feeding 4 onto the page
for (var i = 0; i < results.length; i++) {
var object = results[i];
(function($) {
$('#results-table').append(object.get('objectId') +'<tr><td><b>' + '<img src="' + object.get('Images').url() + '"width="330px">' + '</td><td>' + '<b><p>' + '<a href="recipesContent2.html?' + object.id + '" rel="external">' + object.get('recTitle') + '</a>' + '</b></p>' + '<img src="images/clock.png">' + object.get('Time') + '</td></tr>');
})(jQuery);
}
},
error: function(error) {
alert("Error");
}
});
所以现在我的代码现在是recipesContent2.html页面
Parse.initialize("id","jsid");
var objectId = window.location.pathname.split('?').slice(-1);
var Recipes = Parse.Object.extend("Recipes");
var recipeQuery = new Parse.Query(Recipes);
recipeQuery.exists("Images");
recipeQuery.equalTo("objectId", objectId);
recipeQuery.find({
success: function(results) {
for (var i in results) {
var object = results[i];
(function($) {
$('#results-tab').append(object.get('objectId') +'<tr><td><b>' + '<img src="' + object.get('Images').url() + '"width="330px">' + '</td><td>' + '<b><p>' + object.get('recTitle') + '</b></p>' + '<img src="images/clock.png">' + object.get('Time') + '</td></tr>');
})(jQuery);
}
},
error: function( error) {
alert("Error:" + error.code+ " " + error.message);
}
});
</script>
现在我收到此错误&#34;错误:102平等需要一个值而不是[recipesContent.html]
答案 0 :(得分:0)
您可以像这样创建链接(在您的追加内容中):
.append('<a href="http://mywebsite.com/recipe/' + object.id + '"><img></a>')
在目标页面上,您可以从url获取objectId并进行如下查询:
var objectId = window.location.pathname.split('/').slice(-1);
var Recipes = Parse.Object.extend("Recipes");
var recipeQuery = new Parse.Query(Recipes);
recipeQuery.get(objectId, {
success: function(recipe) {
console.log(recipe);
},
error: function(error) {
console.log('Error');
}
});