任何人都可以解决这个问题。我从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>
}
和jquerymobile代码用于实现类ui-bar divs
..................... ............................
<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;