如何通过属性引用对象的值?

时间:2015-05-31 14:12:10

标签: angularjs x-editable

我有一个像这样的angularjs对象:

$scope.afterLogin = [
    {value: 'customers|follow-ups', text: 'Follow Ups'},
    {value: '', text: 'not set'}
];

我尝试将其与xeditable一起使用,如下所示:

<span
    editable-select="user.default_module"
    e-ng-options="s.value as s.text for s in afterLogin"
    e-name="default_module"
    e-form="rowform">{{s[user.default_module] as s.text for s in afterLogin}}</span>

我想要的是在user.default_module定义的afterLogin中显示text-property。我究竟做错了什么?我在 s [user.default_module]上收到的解析错误 - 如何在此范围内引用对象的属性?

注意:这包含ng-repeat="user in users"

1 个答案:

答案 0 :(得分:1)

您正试图以非常激烈的方式显示当前选定的值。在official example中,他们正在使用过滤器来实现此目的。但是,您可以通过构建 static async Task GoAny() { HttpClientHandler clntHand = new HttpClientHandler() { CookieContainer = new CookieContainer(), Proxy = new WebProxy("http://localhost:8888", false), UseProxy = true, UseDefaultCredentials = false }; HttpClient clnt = new HttpClient(clntHand) { BaseAddress = new Uri("http://localhost:49305") }; clnt.DefaultRequestHeaders.Accept.Clear(); clnt.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage resp = await clnt.GetAsync("api/Employee/12345"); if (resp.StatusCode == System.Net.HttpStatusCode.OK) { string c = resp.Content.ToString(); } } 映射来简化它,即:

value: label

然后,将文本值显示为:

$scope.afterLoginLabels = {};
for (var i = 0; i < $scope.afterLogin.length; i++) {
  $scope.afterLoginLabels[$scope.afterLogin[i].value] = $scope.afterLogin[i].text;   
}

请参阅JSFiddle