在 angularjs 中,我有一个 kendo ui 下拉列表:在我的代码中,当我单击下拉列表中的项目时,我删除了所选项目并将其添加到 html 表中(作为行元素):
$scope.optionsDropDownListCatalogs = {
dataTextField: "Name",
dataValueField: "Id",
select: onSelect
};
function onSelect(e) {
//Get the selected item
var item = $scope.dropdownlistCatalogs.dataItem(e.item.index());
//Remove it from the dropdownlist
$scope.optionsDropDownListCatalogs.dataSource.remove(item);
//Add the item in the table datasource
$scope.products.push(item);
}
在 html 页面中,我有一个ng-repeat来显示对象内部的$scope.product
对象。
有时表会更新,有时不会。如果我把$scope.$apply(); 在函数的末尾,表格(似乎)正确更新。
为什么我必须执行$apply()
?push()
不会发生在同一个摘要中?