jQuery的RATY和AngularJS [英] jQuery Raty and AngularJS

查看:511
本文介绍了jQuery的RATY和AngularJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用的jQuery插件RATY与 AngularJS。没有成功呢。

I'm trying to use jQuery Raty plugin with AngularJS. No success yet.

我需要的是这样的:

<ul>
    <li ng-repeat="obj in collection">
        <p>{{obj.rating}}</p>
        <div id="star{{$index}}"></div>

        <p>{{obj.someText}}</p>

        <script>$("#star{{$index}}").raty();</script>
    </li>
</ul>

但是脚本似乎不被执行,并且它甚至不显示在网页上。此外它看起来还像个极丑的做法,但我没有更多的想法。

But the script seems not to be executed and it doesn't even appear in the webpage. Besides it looks also like a very ugly approach, but I don't have more ideas.

我怎样才能做到这一点?或者我需要为明星不同的插件/功能?

How can I do this? Or do I need a different plugin / functionality for the stars?

推荐答案

如果我不得不这样做,我会制定一个 AngularJS 指令,如:

If I had to do this, I will develop an AngularJS directive, like this:

JS

yourApp.directive("raty", function() {
    return {
        restrict: 'AE',
        link: function(scope, elem, attrs) {
            $(elem).raty({score: attrs.score, number: attrs.number});
        }
    }
}

HTML

<raty id="star{{$index}}" score="1" number="5"></raty>

如果你想添加的RATY一些参数,你可以简单地编辑我的指令;)

If you want add some parameters on Raty, you can edit simply my directive ;)

这篇关于jQuery的RATY和AngularJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆