Angularjs 在网格中使用下拉菜单进行双向绑定

Angularjs 在网格中使用下拉菜单进行双向绑定,angularjs,data-binding,parse-platform,angularjs-scope,Angularjs,Data Binding,Parse Platform,Angularjs Scope,我正在使用AngularJS以及Parse和Parse Angular补丁。我有一个示例应用程序,可以执行基本crud 当我点击编辑按钮时。称呼语失去了它的状态。 以下是相关的HTML: <tbody data-ng-repeat-start="p in people" data-ng-data="who"> <tr> <!-- Salutation -->

我正在使用AngularJS以及Parse和Parse Angular补丁。我有一个示例应用程序,可以执行基本crud

当我点击编辑按钮时。称呼语失去了它的状态。

以下是相关的HTML:

        <tbody data-ng-repeat-start="p in people" data-ng-data="who">
            <tr>
                <!-- Salutation -->
                <td style="min-width:95px;">
                    <span data-ng-hide="editRow == $index">{{p.get('salutation')}}</span>
                    <select data-ng-show="editRow == $index" data-ng-model="model.salutation" class="formControl" data-ng-options="s.label for s in salutations">
                        <option value="">--</option>
                    </select>
                </td>
             ...
                <!-- Action Buttons -->
                <td>
                    <button class="btn btn-xs btn-primary" data-ng-click="onEdit($index)" data-ng-hide="editRow==$index" style="min-width:70px;">
                        <span class="glyphicon glyphicon-pencil "></span>&nbsp;edit
                    </button>
                    ...
当我在控制台中查看$log.debug()语句的结果时,我看到了以下内容

  • cpsal:
  • 史密斯:史密斯博士
此处是控制器的完整源代码:

下拉列表中应选择“Dr.”。你有什么想法可以让它工作吗


这里是完整的项目:

我没有访问您的解析数据的权限,但我模拟了一些静态数据,能够获得列表以填充并在列表中选择适当的项

html:


检查$scope。$watch函数,您已经设置好了……它在我的模型中对称呼进行了重击,所以我对此进行了注释……确保在连接到解析时不会发生同样的事情。

您似乎正在从称呼对象数组中筛选出一些属性。除了标签,s(即称呼语中的s)还有什么其他属性?currentPerson.get(“称呼”)调用是返回整个称呼对象还是只返回标签?它是一个解析对象,因此具有默认的objectId、createdAt、updatedAt和ACL属性以及“label”属性。在这种情况下,重要的是标签。currentPerson.get(“称呼”)返回表示标签的字符串。注释掉$watch没有帮助。如果您将我的项目指向一个空的解析应用程序,它将创建一个问候表,您应该能够准确地看到我看到的内容(如果您感兴趣并且拥有解析帐户)。因为我可以给出正确的值,所以我认为问题在于绑定由于某种原因不能正确触发。这一点得到了加强,因为每次绑定发生时我都会记录日志,当我单击“编辑”时,我看不到日志条目。但是强制$scope.$apply()会导致.Nevermind,绑定事件正在触发;我的$watch在$scope.sallaion上,但我必须在$scope.model.sallation上,这就是为什么我在日志中没有看到任何内容。回到第一步。我所需要做的就是将ng options指令从
“s.label for s in saltations”
更改为
“s.label as s.label for s in saltations”
,就像@terryt在他的例子中所做的那样。谢谢@terryt!!!!
$scope.onEdit = function (ix) {
        $scope.showAdd = false; // hide the add form
        $scope.editRow = ix; // set the index of the row being edited
        var currentPerson = $scope.people[ix]; // grab the current person object 
        $scope.model.fname = currentPerson.get('fname'); // update scope fname
        $scope.model.lname = currentPerson.get('lname'); // update scope lname
        $scope.model.salutation = currentPerson.get('salutation'); // BUG: this doesn't work and I don't know why, it should set the dropdown to the current salutation.
        $log.debug('cpsal: ' + currentPerson.get('salutation'));
        $log.debug('smsal: ' + $scope.model.salutation);
    };
     <select data-ng-show="editRow == $index" data-ng-model="model.salutation" class="formControl" data-ng-options="s.label as s.label for s in salutations">
          <option value="">--</option>
     </select>
$scope.model = { salutation: 'Mr.', fname: 'Tom', lname: 'Jones' }; // our proxy object for the parse data we are crudding
$scope.people = [{salutation: 'Mr.', fname: 'Tom',lname: 'Jones'}];
$scope.salutations = [{label: 'Dr.'}, {label: 'Mr.'}];