'失败:TypeError:运行Parse查询时无法调用undefined'方法'replace'

时间:2014-12-03 00:30:51

标签: javascript parse-platform

每当我运行Parse后台作业时,它都会失败,我会收到以下错误:

Failed with: TypeError: Cannot call method 'replace' of undefined
    at Object.b.Query._quote (Parse.js:3:14236)
    at Object.b.Query.contains (Parse.js:3:14337)
    at main.js:1491:40
    at e (Parse.js:2:5101)
    at Parse.js:2:4651
    at Array.forEach (native)
    at Object.x.each.x.forEach [as _arrayEach] (Parse.js:1:665)
    at c.extend.resolve (Parse.js:2:4602)
    at null.<anonymous> (Parse.js:2:5181)
    at e (Parse.js:2:5101)

这是导致问题的区域,第1491行是最后一行:

var MCI_Results = Parse.Object.extend("MCI_Results");



        var MCI_Results_Comparison_Query = new Parse.Query(MCI_Results);

        // Query for any MCI_Results that have new items

        MCI_Results_Comparison_Query.equalTo('parent', parentUser);

        MCI_Results_Comparison_Query.contains('searchTerm', searchTermsList[i]);

        MCI_Results_Comparison_Query.containedIn('MCItems', top3List[i]);

        MCI_Results_Comparison_Query.find()

          .then(function(results) {

            //No new items                      

            if (results.length > 0) {

              console.log("No new items, you're good to go!");

              //Add user to the "DON'T send push notification" channel

              ////////

              var installationQuery = new Parse.Query(Parse.Installation);

              installationQuery.equalTo('userId', parentUser);


              installationQuery.first()

                .then(function(result) {

                  result.set('channels', ["noPush"]);

                  result.save();

                });

              ///////

              console.log('done updating channel');

            }

            //New items found

            else if (results.length === 0) {

              console.log('no matching MCI_Results, lets push some new shit');

              console.log('searchTermsList[i]:' + searchTermsList[i]);



              var MCI_Results_Update_Query = new Parse.Query(MCI_Results);

              MCI_Results_Update_Query.equalTo('parent', parentUser);

              MCI_Results_Update_Query.contains('searchTerm', searchTermsList[i]);

我在这里所做的就是设置查询的参数,根本不涉及替换方法。是什么导致它说出错误?我进行了三重检查,并且我存在积极的searchTermsList [i],并且MCI_Results对象上的searchTerm属性也存在。

1 个答案:

答案 0 :(得分:1)

对我来说,“修复”(我猜“解决方法”更准确)是避免“包含”并使用“containsIn”代替。它不应该直观,但它似乎可以解决问题。

我想,当谈到数组时,这两种方法都不是它们名称所暗示的集合操作,而是它们只是寻找重叠,因此contains和containedIn之间没有区别?