我正在使用ui-scroll在我的Angular应用程序中实现无限滚动。
它工作正常,我用它来显示事件列表。
但是,当我的应用加载时,它会默认显示第一个事件(实际上是索引HEAD
)。要查看最新事件,必须向下滚动事件列表。当事件列表非常大并且有点击败分页加载时,这是一个问题,因为Web应用程序必须通过所有事件才能获得最新的事件。
如何指示 ui-scroll 从最后的事件开始?显然,我有一个后端方法(一个<ul ui-scroll-viewport class="event-list" ng-class="{loading: eventsLoading}">
<li ui-scroll="event in eventsProvider" data-buffer-size="20" is-loading="eventsLoading">
<p>event.text</p>
</li>
</ul>
请求,我可以用它来获取事件的总数)来获得最初所需的索引。我只是找不到将初始索引放在 ui-scroll 中的方法。
有任何线索吗?
根据要求,这是一个代码示例,虽然它非常“标准” ui-scroll :
$scope.eventsProvider = {
get: function(index, count, success) {
$scope.events = ZoneEventsService.query({
session_type: $scope.session_type,
zone: $scope.zone,
offset: index - 1,
limit: count
}, function(result) {
success(result.items);
});
}
};
以下是我在控制器中的内容:
Function Get-SQLSvrVer {
<#
.SYNOPSIS
Checks remote registry for SQL Server Edition and Version.
.DESCRIPTION
Checks remote registry for SQL Server Edition and Version.
.PARAMETER ComputerName
The remote computer your boss is asking about.
.EXAMPLE
PS C:\> Get-SQLSvrVer -ComputerName mymssqlsvr
.EXAMPLE
PS C:\> $list = cat .\sqlsvrs.txt
PS C:\> $list | % { Get-SQLSvrVer $_ | select ServerName,Edition }
.INPUTS
System.String,System.Int32
.OUTPUTS
System.Management.Automation.PSCustomObject
.NOTES
Only sissies need notes...
.LINK
about_functions_advanced
#>
[CmdletBinding()]
param(
# a computer name
[Parameter(Position=0, Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[System.String]
$ComputerName
)
# Test to see if the remote is up
if (Test-Connection -ComputerName $ComputerName -Count 1 -Quiet) {
$SqlVer = New-Object PSObject
$SqlVer | Add-Member -MemberType NoteProperty -Name ServerName -Value $ComputerName
$base = "SOFTWARE\"
$key = "$($base)\Microsoft\Microsoft SQL Server\Instance Names\SQL"
$type = [Microsoft.Win32.RegistryHive]::LocalMachine
$regKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($type, $ComputerName)
$SqlKey = $regKey.OpenSubKey($key)
try {
$SQLKey.GetValueNames()
} catch { # if this failed, it's wrong node
$base = "SOFTWARE\WOW6432Node\"
$key = "$($base)\Microsoft\Microsoft SQL Server\Instance Names\SQL"
$regKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($type, $ComputerName)
$SqlKey = $regKey.OpenSubKey($key)
}
# parse each value in the reg_multi InstalledInstances
Foreach($instance in $SqlKey.GetValueNames()){
$instName = $SqlKey.GetValue("$instance") # read the instance name
$instKey = $regKey.OpenSubkey("$($base)\Microsoft\Microsoft SQL Server\$instName\Setup") # sub in instance name
# add stuff to the psobj
$SqlVer | Add-Member -MemberType NoteProperty -Name Edition -Value $instKey.GetValue("Edition") -Force # read Ed value
$SqlVer | Add-Member -MemberType NoteProperty -Name Version -Value $instKey.GetValue("Version") -Force # read Ver value
# return an object, useful for many things
$SqlVer
}
} else { Write-Host "Server $ComputerName unavailable..." } # if the connection test fails
}
答案 0 :(得分:1)
我实际上找到了一种方法。在我的控制器中,我推迟第一次加载数据并手动将偏移量偏移事件总数。由于 ui-scroll 处理开箱即用的负偏移,它只是起作用。
$scope.eventsInfo = ZoneEventsService.head({
session_type: $scope.session_type,
zone: $scope.zone,
limit: 0,
});
$scope.eventsProvider = {
get: function(index, count, success) {
// The promise will wait the first time around and be resolved already on following calls.
$scope.eventsInfo.$promise.then(function() {
$scope.events = ZoneEventsService.query({
session_type: $scope.session_type,
zone: $scope.zone,
// Here goes the magic.
offset: index - 1 + $scope.eventsInfo.total_count,
limit: count
}, function(result) {
success(result.items);
});
});
}
};