基本思想是,我具有以下人员类型的项目列表:
@model Calendar.Models.Datepicker
@{
ViewBag.Title = "Create";
}
<h2>Create</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Datepicker</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.DtmDate, htmlAttributes: new { @class
= "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.DtmDate, new { htmlAttributes =
new { @class = "form-control1" } })
@Html.ValidationMessageFor(model => model.DtmDate, "", new {
@class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.UserId, htmlAttributes: new { @class =
"control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.UserId, new { htmlAttributes =
new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.UserId, "", new {
@class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
<link href="~/Content/themes/base/jquery-ui.min.css" rel="stylesheet" />
@section scripts {
<script src="~/Scripts/jquery-ui-1.12.1.min.js"></script>
<script>
jQuery(function(){
var enableDays = ["11-07-2019", "12-07-2019"];
function enableAllTheseDays(date) {
var sdate = $.datepicker.formatDate('dd-mm-yy', date)
console.log(sdate)
if ($.inArray(sdate, enableDays) != -1) {
return [true];
}
return [false];
}
$(".form-control1").datepicker({
dateFormat: "dd/MM/yy",
beforeShowDay: enableAllTheseDays
});
});
</script>
@Scripts.Render("~/bundles/jqueryval")
}
<style>
.my-class a {
background-color: #07ea69 !important;
background-image :none !important;
color: #ffffff !important;
}
</style>
通过按下按钮,我可以根据人的身高或名字来排序此列表,然后调用setState(){}来重建UI。
我还有一个class Person {
int height;
String name;
}
使用ListView.builder()
来显示每个项目,例如:Text()
。
然后我继续创建了一个自定义的有状态小部件,比如说一个PersonDisplay(),我在其中传递要显示在Text()小部件中的person对象,并使用该对象在Text(_persons[index].name)
中显示Persons。>
问题是,如果我这样做,ListView.builder
列表将被排序,但是_persons
项将保持相同的顺序。
我在做错什么吗?