評価プラグインを実装しようとしています。評価プラグインを正常に動作させることができます。私はそれを拡張しようとしています。したがって、評価をクリックするたびに、ラベルが評価自体の下に配置されます。現在、ページの他の場所でcssidにバインドされています。
シナリオはTwitterメッセージであり、メッセージ自体を更新するセレクターを取得できないようです。それはユニークではないので、それらすべてにメッセージを置きます。
どうすればアイテムをユニークにすることができますか。プラグインのドキュメントはhttp://rateit.codeplex.com/documentationです。
$(document).ready(function () {
//we bind only to the rateit controls within the products div
$(".rateit").bind('over', function (event, value) { $(this).attr('title', value); });
$(" .rateit").bind('rated reset', function (e) {
var ri = $(this);
//if the use pressed reset, it will get value: 0 (to be compatible with the HTML range control), we could check if e.type == 'reset', and then set the value to null .
var value = ri.rateit('value');
var ratingid = ri.data('ratingid');
//maybe we want to disable voting?
ri.rateit('readonly', true);
$.ajax({
url: '/Home/GetRating', //your server side script
data: { id: ratingid, value: value }, //our data
type: 'POST',
success: function (data) {
$('#ratemsg').html(data);
},
error: function (jxhr, msg, err) {
$('#response').append('<li style="color:red">' + msg + '</li>');
}
});
});
});
</script>
@foreach (var item in Model)
{
<div id="TwitterMessageBox@(item.StatusId.ToString())" class="TwitterMessageBox">
<ol>
<li class="TweetLineBody">
@Html.Hidden("Statusid", item.StatusId)
<div class="TwitProfileImage">
<img src=@Url.Content(item.ImageUrl) alt="@item.ScreenName" />
</div>
<div class="TwitRealName">
@item.User
</div>
<div class="TwitNickName">
@MvcHtmlString.Create(@Html.Namify(@item.ScreenName))
</div>
<div class="TweetText">
@MvcHtmlString.Create(@item.Tweet)</div>
<div class="TweetTime">
@Html.RelativeDate(@item.Created)</div>
<div id="TweetMessageRating@(item.StatusId.ToString())" name="TweetMessageRating@(item.StatusId.ToString())" class="TweetRating">
// This is where the rating widget goes and records and updates
<div data-ratingid="@item.StatusId" class="rateit"></div>
// this is where i want to go but i cant figure out a way
<span id ="ratemsg" name="TweetRating@(item.StatusId.ToString())" class="ratemsg"> </span>
</div>
</li>
</ol>
</div>
}
上記のように、ステータスIDであるメッセージIDをセレクターに追加して一意のキーを設定しようとしていますが、ワイルドカードを使用して選択できないようです。jqueryサイトでいくつかの例を試しましたが、うまくいかないようです。