我正在使用AngularJS以及Parse和Parse-Angular-Patch。我有一个示例应用程序,它可以处理基本的垃圾。 角度JS双向绑定网格中的下拉列表
当我点击编辑按钮。该称呼失去了它的状态。
下面是相关的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> edit
</button>
...
你可以看到完整的HTML:https://github.com/arcnovus/learning-parse-angular-patch/blob/master/views/crud.html
这里的相关负责人的javascript:
$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);
};
当我看在控制台看到我的$ log.debug()语句的结果,我看到以下内容。
- cpsal:博士
- smsal:博士
的控制器这里完整的源代码:https://github.com/arcnovus/learning-parse-angular-patch/blob/master/controllers/crud.js
下拉应该有 “博士”选择。关于如何使这项工作的任何想法?
全部项目位置:https://github.com/arcnovus/learning-parse-angular-patch
您似乎正在过滤掉salutations对象数组中的某些属性。 s(即在称呼中的s)具有除标签之外的什么属性? currentPerson.get(“salutation”)调用是否返回整个称呼对象或仅返回标签? – ruedamanuel
它是一个Parse对象,因此它具有默认的objectId,createdAt,updatedAt和ACL属性以及“label”属性。在这种情况下,尽管重要的是标签。 currentPerson.get(“salutation”)返回一个表示标签的字符串。 –