当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Document.to_json_string方法代码示例

本文整理汇总了TypeScript中document.Document.to_json_string方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Document.to_json_string方法的具体用法?TypeScript Document.to_json_string怎么用?TypeScript Document.to_json_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在document.Document的用法示例。


在下文中一共展示了Document.to_json_string方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: it

  it("can serialize excluding defaults", () => {
    const d = new Document()
    expect(d.roots().length).to.equal(0)
    const root1 = new SomeModel()
    root1.name = 'bar'
    d.add_root(root1)
    expect(d.roots().length).to.equal(1)

    const json = d.to_json_string(false)
    const parsed = JSON.parse(json)
    parsed.version = js_version
    const copy = Document.from_json_string(JSON.stringify(parsed))

    expect(copy.roots().length).to.equal(1)
    expect(copy.roots()[0]).to.be.an.instanceof(SomeModel)
    expect(copy.roots()[0].name).to.be.equal('bar')

    // be sure defaults were NOT included
    const attrs0 = parsed.roots.references[0].attributes
    expect('tags' in attrs0).to.be.equal(false)
    expect('foo' in attrs0).to.be.equal(false)
    expect('child' in attrs0).to.be.equal(false)
    // this should be included, non-default
    expect('name' in attrs0).to.be.equal(true)

    // double-check different results if we do include_defaults
    const parsed_with_defaults = JSON.parse(d.to_json_string(true))
    const attrs1 = parsed_with_defaults.roots.references[0].attributes
    //expect('tags' in attrs1).to.be.equal(true)
    expect('foo' in attrs1).to.be.equal(true)
    expect('child' in attrs1).to.be.equal(true)
    expect('name' in attrs1).to.be.equal(true)
  })
开发者ID:jsignell,项目名称:bokeh,代码行数:33,代码来源:document.ts

示例2: it

 it("should round-trip through document serialization", () => {
   const d = new Document()
   d.add_root(r)
   const json = d.to_json_string()
   const parsed = JSON.parse(json)
   parsed.version = js_version
   const copy = Document.from_json_string(JSON.stringify(parsed))
   const r_copy = copy.get_model_by_id(r.id)! as CustomJSHover
   const rng_copy = copy.get_model_by_id(rng.id)! as CustomJSHover
   expect(r.values).to.be.deep.equal([rng])
   expect(r_copy.values).to.be.deep.equal([rng_copy])
 })
开发者ID:jsignell,项目名称:bokeh,代码行数:12,代码来源:customjs_hover.ts


注:本文中的document.Document.to_json_string方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。