繁体   English   中英

如何将特定对象解析为用户输入的对象?

[英]How can I replace specific objects in parse to objects inputted by the user?

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

替换部件无法正常工作,并且出现错误“ objects.set不是函数”。 我在做什么错,我该如何更改,以便如果变量“ content”与parse.com中的内容值匹配,则将其替换为“ newlocation”中保存的变量? 先感谢您。

我的代码如下所示:

      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));
        });         

      });

试试objects["newlocation"] = newLocation;

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM