【问题标题】:Return compiled text in d3's text() or html() method在 d3 的 text() 或 html() 方法中返回编译后的文本
【发布时间】:2016-01-26 07:33:04
【问题描述】:

我有以下 d3 代码:

grouping.append('foreignObject').html(function (d) {
  var string = '<p>hello, {{ "there" }} <some-directive></some-directive></p>';
  string = $compile(string)(scope);
  return string;
});

问题是最后,string 是一个实际的 HTML 对象,但 d3 需要它只是一个字符串。我曾尝试使用XMLSerializer 将其转换为文本,但这会将其还原为未编译的原始string

基本上,我需要编译一些元素并将它们作为字符串返回给 d3 方法。我该怎么做?

【问题讨论】:

  • 既然你已经有了实际的 HTML 对象,你可以keep appending吗?

标签: javascript angularjs d3.js


【解决方案1】:

使用 jQuery:

$("<i>").html("<b>Sample</b> text").text() // returns "Sample text"

【讨论】:

  • 不,我需要整个 html 代码作为字符串。我意识到我表达问题的方式可能令人困惑,所以我更新了它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-12-25
  • 1970-01-01
  • 2012-08-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多