【问题标题】:Problems with ng-model while using Angular Chosen使用 Angular Chosen 时 ng-model 的问题
【发布时间】:2017-04-16 21:21:34
【问题描述】:

我有一个包含用户列表的表,其中每一行的最后一列都包含一个按钮。单击按钮时,会出现一个弹出表单。在弹出窗口中,我在 Angular Chosen 的帮助下使用了多项选择。每个用户都有一个“兴趣”列表,我想在多选中显示它们。问题是即使在获取了所有必要的数据之后,ng-model 似乎还是空的。

这是多选。

<select id="multipleSelect"
                    data-placeholder="Select interests..."
                    chosen
                    multiple
                    ng-model="$ctrl.activeInterests" ng-options="interest for interest in $ctrl.interests"
                    style="width:370px; height:100px;">
                    <option value=""></option>
</select>

这是我的组件。该函数在按钮被点击时触发。

this.editButtonClicked = function(tableRowUser) {
                $scope.firstName = tableRowUser.firstName;
                $scope.lastName = tableRowUser.lastName;
                $scope.email = tableRowUser.email;
                $scope.role = tableRowUser.role;
                $scope.tag = tableRowUser.tag;
                $scope.username = tableRowUser.username;

                // Fetch the active interests
                fetchInterests($scope.tag);
                // Fetch the available interests the user can choose
                fetchAllAvailableInterests();
                // After this, make the Edit Form/Popup visible
                togglePopupClass();
            }

function fetchInterests(newInterests) {
                self.activeInterests = [];
                var interests = newInterests.split('|');

                console.log("New interests");
                console.log(newInterests);

                for (i = 0; i < interests.length; i++) {
                    // Trim the excess whitespace.
                    interests[i] = interests[i].replace(/^\s*/, "").replace(/\s*$/, "");

                    self.activeInterests.push(interests[i]);
                }

            }

调用 fetchInterests 后,“activeInterests”包含我希望 ng-model 显示的内容,但视图仍为空。

任何帮助将不胜感激。

【问题讨论】:

    标签: javascript angularjs jquery-chosen angular-chosen


    【解决方案1】:

    找到解决方案。您希望在 ng-model 中显示的内容也应该始终在 ng-options 中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-02
      • 2016-09-24
      • 2015-07-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多