我用Knockout做了什么,我正在尝试使用Angular.
在我当前的项目中,我有一个表,通过scroll事件添加数据.当用户向下滚动时,我在表的末尾添加20行,总行数可以达到2k-10k.我开始显示20条记录,当用户向下滚动时,我会继续添加20行,直到达到总行数.
正如在我的Angular小提琴示例中,当使用重复时,如果将新数据推送到数组''Angular'执行所有记录并再次渲染它们但是敲除只是执行并呈现新添加的记录.在我的项目中因为我显示数千这种方式的角度有效,或者我认为它的工作方式会影响我的表现.
我只用了几个星期才使用角度我不知道如果我做错了什么或者我需要修改一些东西.
<h2>Your seat reservations</h2>
<table>
<thead><tr>
<th>Passenger name</th><th>Meal</th><th>Test</th>
</tr></thead>
<tbody data-bind="foreach: seats()">
<tr>
<td data-bind="text: mealName"></td>
<td data-bind="text: price"></td>
<td data-bind="text: $root.cellAdded()"></td>
</tr>
</tbody>
</table>
<button data-bind="click: $root.PushData()">I am Here</button>
Run Code Online (Sandbox Code Playgroud)
JS:
// Overall viewmodel for this screen, along with initial state
function ReservationsViewModel() {
var self = this;
self.cellAdded = function(){
console.log('Test Added');
return 'ok';
};
self.PushData = function(){
console.log('PushData Called');
self.seats.push({ mealName: "Standard (sandwich)", price: 0 });
};
// Editable data
self.seats = ko.observableArray([ …Run Code Online (Sandbox Code Playgroud) [Table("UserMaster")]
public class UserMaster
{
public UserMaster()
{
this.Roles = new List<Role>();
}
[Key]
public int UserId { get; set; }
public string UserName { get; set; }
public ICollection<Role> Roles { get; set; }
}
[Table("Role")]
public class Role
{
public Role()
{
this.Users = new List<UserMaster>();
}
public int RoleId{ get; set; }
public string Name{ get; set; }
public ICollection<UserMaster> Users { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我使用EntityTypeConfiguration映射这些表,并触发OnModelCreate
this.HasMany(a => a.Roles).WithMany(b => b.Users).Map(m =>
{
m.MapLeftKey("UserId");
m.MapRightKey("RoleId");
m.ToTable("UsersInRoles"); …Run Code Online (Sandbox Code Playgroud)