gpt4 book ai didi

AngularJS : ui-grid field with a concatenation of two fields

转载 作者:行者123 更新时间:2023-12-02 11:28:26 24 4
gpt4 key购买 nike

我需要 ui-grid 中的一列,它是两个字段的串联,例如“名称”和“地址”。我怎样才能实现这个目标?

最佳答案

你尝试过这种方法吗?

Controller

var app = angular.module('myApp', ['ngGrid']);
app.controller('MyCtrl', function($scope) {
$scope.myData = [
{name: "Moroni", address: test1},
{name: "Tiancum", address: test2},
{name: "Jacob", address: test3},
{name: "Nephi", address: test4},
{name: "Enos", address: test5 }];

angular.forEach($scope.myData,function(row){
row.getNameAndAddress = function(){
return this.name + '-' + this.address;
}
});

$scope.gridOptions = {
data: 'myData',
columnDefs: [{field: 'name', displayName: 'Name'},
{field:'address', displayName:'Address'},
{field: 'getNameAndAddress()', displayName: 'Name and address'},
]
};
});

html

<body ng-controller="MyCtrl">
<div class="gridStyle" ng-grid="gridOptions"></div>
</body>

关于AngularJS : ui-grid field with a concatenation of two fields,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39404002/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com