如何在x-editable angularjs的select下拉列表中获得所选值

How do i get the selected value in select dropdown of x-editable angularjs

本文关键字:下拉列表 select x-editable angularjs      更新时间:2023-09-26

我在angularjs中使用x-editable。

当我提交选择时。

我没有得到文件中给出的$data的新值

这是小提琴http://jsfiddle.net/NfPcH/7014/

脚本:

var app = angular.module("app", ["xeditable", "ngMockE2E"]);
app.run(function(editableOptions) {
  editableOptions.theme = 'bs3';
});
app.controller('Ctrl', function($scope, $q, $http) {
  $scope.items = ['a','b','c'];
  $scope.user = {
    id: 1,
    name: 'a'
  };
  $scope.updateUser = function(data) {
      alert(data);
     $scope.console = data;
    return $http.post('/updateUser', {id: $scope.user.id, name: data});
  };
});
// mock `/updateUser` request
app.run(function($httpBackend) {
  $httpBackend.whenPOST(/'/updateUser/).respond(function(method, url, data) {
    data = angular.fromJson(data);
    if(data.name === 'error') {
      return [500, 'Error message']; 
    } else {
      return [200, {status: 'ok'}]; 
    }
  });
});

有人能帮我吗?我如何获得更新的价值?

您的问题是试图读取html中的s.text,但您的数组中没有文本键!

更改。。。。

ng-options="s.text as s for s in items"

ng-options="s for s in items"

它似乎起了作用。

http://jsfiddle.net/v983ryrk/1/