English 中文(简体)
如何用 SVG 部件绑定数据
原标题:AngularJS how to bind data with SVG widget

我知道这通常不是使用角JS的方法,但我想知道我想实现的目标是否与角JS有关。如果这不是推荐的方法,请就如何实现这一目标提供提示?请把我视为网络编程领域的新人。

所以在我的工程中, 我使用 SVG & amp; RaphaelJS 在“ 持单人” div 内放置的画布上绘制几个部件。 我正试图用 AgragleJS 将这些部件与数据绑在一起, 基本上每个部件都与自定义控制器中的对象连接。 当我初始化部件时, 我如何访问海关控制器?

<html lang="en" style="height: 100%;"  ng-app="myApp">
<head>
  <script type="text/javascript"">
    $(document).ready(function () {
      var canvas = Raphael( holder ,  800 ,  600 );
      var widget1 = new Widget1(params);
      // initialize widgets here, that I need to bind to data using AngularJS
      // I am not able to access the CustomController here when drawing my widgets
    });
  </script>
</head>
<body>
  <div id="holder" ng-controller="CustomController">

  </div>
</body>
</html>

使用 AgnajJS 实现 SVG 部件数据约束是否在此? 我开始觉得这不是 AgnajJS 的目的。

<强 > UPATE:

伙计们非常感谢你们的回答! 要求是部件接受用户输入, 我希望它不会被放置在 html 文件( 模块化目的) 。 因此指令似乎是目前的首要选择 。 在链接方法中, 我将使用 RaphaelJS 来绘制部件, 我也可以绘制可编辑对象, 但是这样我就不会适当地使用 AgreanJS 绑定机制, 只是监视器和事件处理器... 对我来说似乎很乱。 如果能用某种方式把 SVG 标记放进指令的模板属性中, 并在模板中标出标注, 但它似乎不支持 。

你们有其他想法吗?

Btw 是否有办法在 jQuery 获得的属性和 HTML 元素( 如文本框) 之间按程序应用绑定?

观 观 观

最佳回答

您可以找到控制器, 但这将使 SVG 和您的应用程序之间的整个通信在侧侧外。 相反, 反转了应用程序的构成方式 : 允许以角驱动应用程序, 并用指令将 svg 包装为可重复使用的组件, 正如 Dan 所提到的 。

使用 SVG 和 角的 btw 使用 SVG 和 角并不罕见。 请看这个非常惊人的例子 : < a href="http://sullerandras.github.com/SVG- Sequence- Diagram/"

问题回答

您应该查看创建一个覆盖这些对象的角形指令。 当数据与角形范围相关时, 您需要做一个范围 $$appply ()。 这是一个简单化的回答, 请查看 < a href=" http://docs. agrejs. org/ guide/ directive" rel = “ nofollow” > http://docs. agregnjs.org/ guide/ directive doc 。





相关问题
How to bind a TabControl to an ObservableCollection in XAML

I have the following line of code in my code-behind class. TabControl.ItemsSource = ((MainWindowViewModel)DataContext).TabItemViewModels; I would like to move this to the XAML file. In brief, ...

Bind to ancestor of adorned element

Here is the case: <DataTemplate x:Key="ItemTemplate" DataType="local:RoutedCustomCommand"> <Button Command="{Binding}" Content="{Binding Text}" ...

LINQ to SQL as databinding source for WPF Treeview

I wonder if someone could provide a simple example of the following. (preferably in VB.Net): I have an SQL database with related tables and I am successfully using LINQ to SQL in other areas of my ...

Qt equivalent of .NET data binding?

Is there an equivalent of .NET s data binding in Qt? I want to populate some combo boxes and other widgets with QStrings that refer to specific entities in my database. However, it would be cleaner ...

WPF TreeView binding through XAML

So I have a class structure like this Store Owner Cashier List of Products Product Name Price List of Vendors Company Name Contact Name So there are 4 ...

热门标签