如何将特定对象解析为用户输入的对象? [英] How can I replace specific objects in parse to objects inputted by the user?

查看:68
本文介绍了如何将特定对象解析为用户输入的对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Parse中有一个名为"Post"的对象,在其中,我有一个名为"title"和"content"的列.我正在尝试向用户询问输入值,并将其另存为变量,也称为内容".如果用户的输入值(内容")与parse.com中已保存的内容"值匹配,我想用保存在"newlocation"中的变量替换parse.com中的内容"值(也由用户输入) ).

I have objects in Parse called "Post" and within that, I have columns called "title" and "content". I am trying to ask the user for an input value and save this as a variable, also called "content". If the user's input value ("content") matches a "content" value already saved in parse.com, I want to replace the "content" value in parse.com with the variable saved in "newlocation" (also inputted by the user).

替换部分不起作用,并且出现错误"objects.set不是函数".我在做什么错,我该如何更改,以便如果变量"content"与parse.com中的内容值匹配,则将其替换为"newlocation"中保存的变量?预先谢谢你.

The replacing part is not working and I am getting the error "objects.set is not a function". What am I doing incorrectly and what can I change so that if the variable "content" matches a content value in parse.com, it is replaced with the variable saved in "newlocation"? Thank you in advance.

我的代码如下所示:

      function postsSameAs(content){
          var Post = Parse.Object.extend("Post");
          var query = new Parse.Query(Post);
          query.equalTo("content", content);
          return query.find();

      } 

      $("#post-form-change").submit(function(event){
        event.preventDefault();

        var content = $("#post-original").val();
        var newlocation = $("#post-new").val();

        postsSameAs(content).then(function(objects){
            console.log("replacing " + JSON.stringify(objects));
            objects.set("newlocation", newlocation);  //should replace the "content" value in parse.com to the variable saved in "newlocation"

            return objects.save();
            window.alert("You have successfully replaced " + content + " to " + newlocation);
        }, function(error) {
            console.log("error " + JSON.stringify(error));
        });         

      });

推荐答案

代码的问题是find()解析为匹配对象的数组. objects.set(...不好,因为对象是一个数组.您是否希望查询中只有一个帖子?在这种情况下,将query.find()替换为query.first()

The problem with the code is that find() resolves as an array of matching objects. objects.set(... is no good because objects is an array. Do you expect only one Post from the query? In that case, replace query.find() with query.first()

这篇关于如何将特定对象解析为用户输入的对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆