Javascript Eval绑定

时间:2018-01-23 11:10:03

标签: javascript jquery arrays eval

var data = $.grep(list, function (item, index) {
  return eval(paramBuilder);
});

此代码语句在我的本地工作,当我部署到服务器时,它会出现此错误。

  

VM11410:1未捕获的ReferenceError:未定义项目
          在eval(eval at(application?v = c1cfyuXKgZC7JWR4mYcqCA8SX3ZBMMTjNBykdPM3mQ41:1),:1:1)

如果我将声明改为此声明,则表明它已成功运作。

var data = $.grep(list, function (item, index) {
  console.log(item);
  return eval(paramBuilder);
});

为什么我收到此错误?

1 个答案:

答案 0 :(得分:0)

 IsHaveObject: function (list, object, properties) {
    if (Validator.IsValidObject(list)) {
        var paramBuilder = "";
        $.each(properties, function (index, item) {
            var value = "";
            if (object[item] === null)
                value = null;
            else if (typeof (object[item]) === 'number')
                value = object[item];
            else if (typeof (object[item]) === 'string')
                value = "'" + object[item] + "'";
            paramBuilder = paramBuilder + "forBug." + item + "===" + value + "&&";
        });
        paramBuilder = paramBuilder.substr(0, paramBuilder.length - 2);
        var data = $.grep(list, function (item, index) {
            var forBug = item;
            return eval(paramBuilder);
        });
        return data.length > 0 ? true : false;
    } else
        return true;
},

我添加了var forBug = item,例如console.log,但很遗憾。