我有一个搜索表单,每当其中一个字段发生变化时,我想自动更新结果。我想限制JSON请求到服务器的速度。我该怎么做?
示例
[Name] [Age] [Subjects]
=======================
// Results automatically updated
答案 0 :(得分:1)
使用ng-model-options延迟调用搜索,如此
SELECT
dbo.cc_tCC_Master.CCMasterID, dbo.cc_tCC_Master.BU, MIN(dbo.cc_qAARDT_Master.Area) AS Area,
MIN(dbo.cc_qAARDT_Master.[Area Name]) AS [Area Name],
MIN(dbo.cc_qAARDT_Master.Region) AS Region,
MIN(dbo.cc_qAARDT_Master.[Region Name]) AS [Region Name], MIN(dbo.cc_qAARDT_Master.District) AS District,
MIN(dbo.cc_qAARDT_Master.[District Name]) AS [District Name], MIN(dbo.cc_qAARDT_Master.Territory) AS Territory,
MIN(dbo.cc_qAARDT_Master.[Territory Name]) AS [Territory Name], dbo.cc_tCC_Master.Therapy, dbo.cc_tCC_Master.Location, dbo.cc_tCC_Master.Location_Name,dbo.cc_tCC_Master.Location_Type,
dbo.cc_tCC_Master.CC_Start_Date, dbo.cc_tCC_Master.CC_End_Date, dbo.cc_tCC_Master.Template_Sent_Date, dbo.cc_tCC_Master.Scan_Received_Date, dbo.cc_tCC_Master.Scan_Upload_Date, dbo.cc_tCC_Master.Scan_Type, dbo.cc_tCC_Master.Master_Reconciled_Date, dbo.cc_tCC_Master.Date_Discrepancies_Processed, dbo.cc_tCC_Master.Status, dbo.cc_tStatus_Codes.Status_Value, dbo.cc_tCC_Master.Comments, dbo.cc_tCC_Master.Last_Updated_user,
SUM(CASE WHEN (isnull(LEFT(dbo.cc_tCC_Audit.Plant, 1), 'x') <> 'Z' OR dbo.cc_tCC_Area.Count_Fixed_Assets = 1) THEN isnull(dbo.cc_tCC_Audit.[SAP Qty], 0) ELSE 0 END) AS [SAP Inv],
SUM(CASE WHEN isnull(dbo.cc_tCfnSerialLotOverride.Override_Value, rr.Serial_Lot_Flag) = 'S' AND (isnull(LEFT(dbo.cc_tCC_Audit.Plant, 1), 'x') <> 'Z' OR dbo.cc_tCC_Area.Count_Fixed_Assets = 1) THEN isnull(dbo.cc_tCC_Audit.[SAP Qty], 0) ELSE 0 END) AS [SAP Serial Inv],
SUM(CASE WHEN isnull(dbo.cc_tCfnSerialLotOverride.Override_Value, rr.Serial_Lot_Flag) = 'L' AND (isnull(LEFT(dbo.cc_tCC_Audit.Plant, 1), 'x') <> 'Z' OR dbo.cc_tCC_Area.Count_Fixed_Assets = 1) THEN isnull(dbo.cc_tCC_Audit.[SAP Qty], 0) ELSE 0 END) AS [SAP Lot Inv]
CASE WHEN dbo.cc_tCC_Audit.CFN = dbo.[ru_t_FDA Tracked Items].[Product Number] THEN isnull(dbo.cc_tCC_Audit.[CC Qty], 0) ELSE 0 END AS [FDA Inv]
FROM dbo.cc_tStatus_Codes INNER JOIN dbo.cc_tCC_Master LEFT OUTER JOIN dbo.cc_tCC_Audit ON dbo.cc_tCC_Master.CCMasterID = dbo.cc_tCC_Audit.CCMasterID ON dbo.cc_tStatus_Codes.Status_Code = dbo.cc_tCC_Master.Status LEFT OUTER JOIN dbo.cc_tCfnSerialLotOverride ON dbo.cc_tCC_Audit.CFN dbo.cc_tCfnSerialLotOverride.CFN LEFT OUTER JOIN
dbo.[rt_t_FDA Tracked Items].[Product Name] ON dbo.cc_tCC_Audit.CFN = dbo.[rt_t_FDA Tracked Items].[Product Name] LEFT OUTER JOIN
dbo.cc_qAARDT_Master ON dbo.cc_tCC_Master.Territory = dbo.cc_qAARDT_Master.Territory AND dbo.cc_tCC_Master.BU ISNULL(dbo.cc_qAARDT_Master.BU,dbo.cc_tCC_Master.BU) INNER JOIN
dbo.cc_tCC_Area ON dbo.cc_tCC_Area.CCArea = dbo.cc_tCC_Master.BU LEFT OUTER JOIN (SELECT DISTINCT AuditID, Serial_Lot_Flag FROM dbo.cc_tCC_ResearchResults) AS rr ON rr.AuditID = dbo.cc_tCC_Audit.AuditID
GROUP BY
dbo.cc_tCC_Master.CCMasterID, dbo.cc_tCC_Master.BU, dbo.cc_tCC_Master.Therapy, dbo.cc_tCC_Master.Location, dbo.cc_tCC_Master.Location_Name,dbo.cc_tCC_Master.Location_Type, dbo.cc_tCC_Master.CC_Start_Date, dbo.cc_tCC_Master.CC_End_Date, dbo.cc_tCC_Master.Template_Sent_Date,dbo.cc_tCC_Master.Scan_Received_Date, dbo.cc_tCC_Master.Scan_Upload_Date, dbo.cc_tCC_Master.Scan_Type, dbo.cc_tCC_Master.Master_Reconciled_Date,dbo.cc_tCC_Master.Date_Discrepancies_Processed, dbo.cc_tCC_Master.Status, dbo.cc_tStatus_Codes.Status_Value, dbo.cc_tCC_Master.Comments,dbo.cc_tCC_Master.Last_Updated_user,
CASE WHEN dbo.cc_tCC_Audit.CFN = dbo.[ru_t_FDA Tracked Items].[Product Number] THEN isnull(dbo.cc_tCC_Audit.[CC Qty], 0) ELSE 0 END
将其添加到每个文本框
ng-model-options="{debounce: {'default': 1000, 'blur': 0}}"
它不会在1秒后更新值,或者您离开控件。
Name: <input type="text" ng-model="student.name"
ng-model-options="{debounce: {'default': 1000, 'blur': 0}}">
Age: <input type="text" ng-model="student.age"
ng-model-options="{debounce: {'default': 1000, 'blur': 0}}">
Subject: <input type="text" ng-model="student.subject"
ng-model-options="{debounce: {'default': 1000, 'blur': 0}}">
答案 1 :(得分:-1)
假设您有一个搜索系统,可以搜索
<h1>Student Search</h1>
Name: <input type="text" ng-model="student.name">
Age: <input type="text" ng-model="student.age">
Subject: <input type="text" ng-model="student.subject">
控制器代码:
$scope.$watchCollection('student', function() {
$timeout.cancel($scope.delayedRequest);
$scope.delayedRequest = $timeout(function() {
// REST Request in here!
}, 1000);
})