任何人都可以解决这个问题吗。我从 ids 和百分比的操作中获取两个数组我尝试了所有编码但没有成功但输出不正确
javascript代码
@section javascript{
<script type="text/javascript">
$(document).ready(function() {
var percents = @Html.Raw(Json.Encode(ViewBag.percentage));
var ids = @Html.Raw(Json.Encode(ViewBag.IDs));
var date = new Date();
var day = date.getDay();
var dayper = (day / 30) * 100;
$.each(ids, function(index, id) {
var percent = parseInt(percents[index], 10);
var element = $('#' + id);
element.css('width', percent + '%');
var rA = 100 - percent;
var color = 'green';
if (rA - dayper > 40) {
color = 'red';
} else if (rA - dayper > 20 && rA - dayper < 40) {
color = 'yellow';
}
element.css('background-color', color);
});
});
</script>
}
和用于实现类 ui-bar div 的 jquerymobile 代码
……………………………………………………………………………………………………………………
<div class="ui-bar-e" id="bdgt_@(item.budgetId)" >
@Model.currency[l]@item.spentAmount/@Model.currency[l]@item.amount
</div>
………………………………………………………………………………………………………………………………………………………………………………………………………… .....................
这里有什么错误
从评论编辑
在行动:
string[] IDs = new string[bEList.Count];
int i = 0;
foreach(var item in bEList) {
IDs[i] = "bdgt_" + item.budgetId;
i++;
}
ViewBag.IDs = IDs;