【问题标题】:Is it possible to do string-replacements in RavenDB javascript-patches?是否可以在 RavenDB javascript-patches 中进行字符串替换?
【发布时间】:2017-05-10 03:05:03
【问题描述】:

案例:当产生新的开发环境时,我想浏览一些集合并更改某些字符串值中的 TLD,例如“bla bla mydomain.com” 变为 “bla bla mydomain.localhost”

我只是在 Raven Studio 的补丁窗口中尝试过:

this.MyProperty = this.MyProperty.replace(".com", ".localhost");

但我得到了:

TypeError: 对象的属性“替换”不是函数

在那之后我去了the docs,在那里确实似乎字符串替换不是一种选择。

我的问题是:是否有可能以任何方式在 RavenDB 的 js-patches 中进行字符串替换?

【问题讨论】:

    标签: ravendb ravendb-studio


    【解决方案1】:

    这应该可以工作:

    this.Name = this.Name.replace("food", "drink");
    

    我刚刚在http://live-test.ravendb.net/studio/index.html#databases/patch/recentpatch--374082468?&database=Northwind 上对其进行了测试,它确实有效。

    但是,请确保该属性确实存在并且是字符串类型。

    【讨论】:

      【解决方案2】:

      啊 - 5分钟后发现:

      _.replace(this.MyProperty, ".com", ".localhost");
      

      作为docs say,下划线_ 引用lodash library(hashtag rtfm)

      【讨论】:

      • lodash 有效。但是, .replace 也可以。我猜你只需要做一个空或未定义的检查,例如if (this.Name) { this.Name.replace(...) }
      猜你喜欢
      • 2015-08-05
      • 1970-01-01
      • 2021-09-25
      • 1970-01-01
      • 2011-10-04
      • 1970-01-01
      • 2016-12-19
      • 1970-01-01
      • 2013-12-07
      相关资源
      最近更新 更多