我正在构建一个带模态窗口的AngularJS Web应用程序.在模态窗口中,我可以显示一个
JQuery Flot实时图表,类似于:
http://people.iola.dk/olau/flot/examples/realtime.html
http://people.iola.dk/olau/flot/examples/realtime.html
我的网站显示多个用户,但根据所选内容,用户数可能会有所不同.我想为每个用户显示一个图表.这是我难倒的地方.
我从http://people.iola.dk/olau/flot/examples/realtime.html复制了Javascript代码并将其放在/js/flot/flot.user.js中,并进行了以下更改:
//$(function () { function flotChart(user_ID) { ... //var plot = $.plot($("#placeholder"),[ getRandomData() ],options); var plot = $.plot($("#chart_" + user_ID),options); …
我的AngularJS网络应用程序有以下代码:
在index.app.html中:
<!DOCTYPE HTML> <html ng-app="app"> ... <body ng-controller="AppCtrl"> ... <div class="container"> <div ng-view></div> </div> ...
在模板(index.html)中:
... <!-- Modal window --> <script src="/js/flot/flot.user.js"></script> <table class="table table-condensed"> <tr ng-repeat="user in users"> <td ng-click="href('#/profile/'+user.user_ID)" data-dismiss="modal">{{user.user_name}}</td> <td> <script type="text/javascript"> flotChart({{user.user_ID}}); </script> <div id="chart_{{user.user_ID}}" style="width:100%;height:150px;"></div> </td> ...
我需要将{{user.user_ID}}传递给flotChart(user_ID),但如上所示,flotChart({{user.user_ID}})不起作用.
有人可以提出解决方案吗?
解决方法
@H_404_39@ 我喜欢blesh建议使用指令,但建议稍微处理一下(对不起,我现在没有带宽).对于你拥有的代码,我认为你所需要的只是一个小小的调整.<td ng-click="href('#/profile/{{user.user_ID}}')" data-dismiss="modal">{{user.user_name}}</td>
封装在一个指令中是一个更好的解决方案,但是,如果你需要看到它工作,那么我认为这是可以的 – 现在.如果这对你有用,请告诉我.
– 担