本文整理匯總了TypeScript中@bokehjs/document.Document.to_json_string方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Document.to_json_string方法的具體用法?TypeScript Document.to_json_string怎麽用?TypeScript Document.to_json_string使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類@bokehjs/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)
})
示例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])
})