一个常见的场景,我有一个以ng-repeat显示的项目集合.对于显示的每一行,我都有一个启动进程(文件上载)的按钮和一个状态字段.我希望我的UI能够在过程状态发生变化时进行反映.这在Angular w /双向绑定中应该很容易,对吧?
我在ng-repeat上创建了一个第二个(子)控制器,这样我就可以简单地更新它自己范围内的项目状态,而不是处理项目集合,特别是因为这个过程是异步的,用户可能会上传很多文件并发.
问题:我对Ang/JS中的$ scope的理解缺乏 - 大声笑.但是,严重的是,当更新范围模型值时,UI中的绑定{{xxx}}值不会更新.单击任一按钮并观察警报.如何让UI正确更新?
仅供参考 - 实际上该按钮调用外部库上的API来上传文件并返回给我一个URL以检查我上传的状态.然后我在setInterval()循环中轮询url以ping状态直到完成或错误.我已经简化了Plunkr中的那个部分,因为这种复杂性本身不是问题. Plunkr
<!DOCTYPE html>
<html ng-app="myapp">
<head>
<meta charset="utf-8" />
<title>AngularJS Plunker</title>
<script>document.write('<base href="' + document.location + '" />');</script>
<link rel="stylesheet" href="style.css" />
<script data-require="angular.js@1.2.x" src="http://code.angularjs.org/1.2.7/angular.js" data-semver="1.2.7"></script>
<script src="app.js"></script>
</head>
<body ng-controller="MainCtrl">
<table>
<th></th>
<th>Id</th>
<th>Name</th>
<th>Status</th>
<tr ng-repeat="item in items" ng-controller="ChildCtrl">
<td><button ng-click="updateStatus(item)">click</button></td>
<td>{{item.id}}</td>
<td>{{item.name}}</td>
<td>{{item.status}}</td>
</tr>
</table>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
JS
var app = angular.module('myapp', []);
app.controller('MainCtrl', function($scope) {
$scope.items = [ {id: 1, name: "Moe", status: "init"} …Run Code Online (Sandbox Code Playgroud) 运行Enterprise Library 5.0的示例,当我使用ExecuteNonQuery运行更新sproc时,它返回2.更新基于ProductID,表的主键(是的,我检查过,它是唯一的).
这是简单的sproc:
ALTER PROCEDURE [dbo].[UpdateProductsTable]
@ProductID int,
@ProductName varchar(50) = NULL,
@CategoryID int = NULL,
@UnitPrice money = NULL
AS
BEGIN
UPDATE Products
SET
ProductName = @ProductName,
CategoryID = @CategoryID,
UnitPrice = @UnitPrice
WHERE ProductID = @ProductID
END
Run Code Online (Sandbox Code Playgroud)
在SSMS中执行此sp在查询结果窗口的右下角显示"1行",并在网格中返回0.单击消息选项卡显示
(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)
Run Code Online (Sandbox Code Playgroud)
不知道为什么我在这里看到这3次,但我不相信这是问题所在.
这是调用sp的代码:
public static void Exec_Update_Query()
//updates a column of a single row, checks that the update succeeded, and then update it again to return it to the original value …Run Code Online (Sandbox Code Playgroud)