Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript angularjs-更新'acute.选择'ac change'后的'list'`_Javascript_Angularjs - Fatal编程技术网

Javascript angularjs-更新'acute.选择'ac change'后的'list'`

Javascript angularjs-更新'acute.选择'ac change'后的'list'`,javascript,angularjs,Javascript,Angularjs,我正在使用acute。在我的angularjs项目中选择。我有一个数组: $scope.users = []; $scope.acuteusers =[{UserName:"john"},{UserName:"joe"},{UserName:"mary"}]; $scope.stateSelected = function(state){ console.log(state); for (var i = 0; i < $sc

我正在使用
acute。在我的
angularjs
项目中选择
。我有一个
数组

$scope.users = [];
$scope.acuteusers =[{UserName:"john"},{UserName:"joe"},{UserName:"mary"}];

        $scope.stateSelected = function(state){
            console.log(state);
            for (var i = 0; i < $scope.acuteusers.length; i++) {
                if (state.UserName == $scope.acuteusers[i].UserName) {
                    $scope.acuteusers.splice(i,1);
                };
            };
            console.log($scope.acuteusers);
        }

我想从
acute中取出元素。选择
下拉列表,列出所选元素的所有内容。但不知何故,它将保持初始状态(没有删除任何元素),即使
console.log
显示它已经被删除。如何解决这个问题?

在阅读了大量关于指令(,)的独立作用域的内容后,我决定破解
acute.select.js
指令

首先,我在
acute.select.js
中添加了一个新的
范围数据

.directive("acSelect", function($parse, acuteSelectService) {
    var defaultSettings = acuteSelectService.getSettings();
    return {
        restrict: "EAC",
        scope: {
            "acSettings": "@",
            "acOptions": "@",
            "model": "=acModel",
            "acChange": "&",
            "keyField": "@acKey",
            "acRefresh": "=",///I believe you can use this, but no documentation at all.
            "acFocusWhen": "=",
            "id": "@",
            data:"=acuteOptions"///newly added by me.
        },
replace: true,
        templateUrl: defaultSettings.templatePath + "acute.select.htm",
        link: function(scope, element, attrs) {
            scope.initialise();

            ///**Then I added in $watchCollection to watch the `data` changes.
            scope.$watchCollection('data', function(newVals, oldVals) {
            ///**I found out scope.allItems is the array to build and display the list. 
///however it must follow {text,value,index} object format. So I reformat it that way.
            scope.allItems = [];
            for (var i = 0; i < newVals.length; i++) {
          scope.allItems.push({text:newVals[i].UserName,value:newVals[i],index:i});
            };
            }, true);
        },
现在,只要
$scope.acuteuser
发生更改,它就会更改下拉列表


我仍然相信,
acRefresh
可以做这项工作,但我就是不知道怎么做。如果有人能分享一个更强大的解决方案,那就太好了。

这可能是您的
ac-
中的问题。在拼接过程中添加$timeout有时触发
$digest
需要时间。我认为拼接应该类似于$scope.acuteusers.splice(i,1);不要在迭代数组时修改它,它是一种反模式。如果在迭代数组时必须从数组中删除元素,请向后执行(使用
array.len
和减量启动计数器)。@AnikIslamAbhi添加了
$timeout
,结果仍然相同。它看起来像是
acute。选择
在它自己的范围内有一组数组。我注意到有一个
acRefresh
选项。如何使用它?
.directive("acSelect", function($parse, acuteSelectService) {
    var defaultSettings = acuteSelectService.getSettings();
    return {
        restrict: "EAC",
        scope: {
            "acSettings": "@",
            "acOptions": "@",
            "model": "=acModel",
            "acChange": "&",
            "keyField": "@acKey",
            "acRefresh": "=",///I believe you can use this, but no documentation at all.
            "acFocusWhen": "=",
            "id": "@",
            data:"=acuteOptions"///newly added by me.
        },
replace: true,
        templateUrl: defaultSettings.templatePath + "acute.select.htm",
        link: function(scope, element, attrs) {
            scope.initialise();

            ///**Then I added in $watchCollection to watch the `data` changes.
            scope.$watchCollection('data', function(newVals, oldVals) {
            ///**I found out scope.allItems is the array to build and display the list. 
///however it must follow {text,value,index} object format. So I reformat it that way.
            scope.allItems = [];
            for (var i = 0; i < newVals.length; i++) {
          scope.allItems.push({text:newVals[i].UserName,value:newVals[i],index:i});
            };
            }, true);
        },
<select class="ac-select stateList" ac-model="users" acute-options="acuteusers" ac-options="s.UserName for s in acuteusers" 
        ac-settings="{ comboMode: true, loadOnOpen: true, minWidth: '470px' }" ac-change="stateSelected(value)" >
      </select>