Javascript 对象的顺序已更改
我想绑定动态数据,绑定数据后,数据的顺序会发生变化Javascript 对象的顺序已更改,javascript,angularjs,json,angularjs-ng-repeat,Javascript,Angularjs,Json,Angularjs Ng Repeat,我想绑定动态数据,绑定数据后,数据的顺序会发生变化 var-app=angular.module(“mainApp”,[]); 应用程序控制器('mainCtrl',函数($scope){ $scope.fieldNames={author_name:“author name”,about_author:“about author”,author_image:“author image”}; $scope.authors=[{author_name:'akshay',about_author:
var-app=angular.module(“mainApp”,[]);
应用程序控制器('mainCtrl',函数($scope){
$scope.fieldNames={author_name:“author name”,about_author:“about author”,author_image:“author image”};
$scope.authors=[{author_name:'akshay',about_author:'this about author',author_image:'image url here'}];
log($scope.authors);
});代码>
{{fieldNames[key]}
您应该始终明确定义属性名称,因为不能保证为每个循环(如ng repeat)排序
因此,我建议使用单个循环(而不是嵌套循环),如下所示:
<div ng-repeat="author in authors" class="authorAndTagGroup">
<label class="col-sm-3 control-label">Author Name</label>
<input type="text" ng-model="author_name">
<label class="col-sm-3 control-label">About Author</label>
<input type="text" ng-model="about_author">
<label class="col-sm-3 control-label">Author Image</label>
<input type="text" ng-model="author_image">
</div>
作者姓名
关于作者
作者形象
当我将角度版本1.2.23更改为1.5.3时,问题得到解决。是的,如果使用解决此问题的更高版本(例如->1.5.3
),问题将得到解决
我建议你看一下迁移文档。它将帮助你避免将来的问题
:
由于之前使用NGTO时项目的顺序重复
迭代对象属性是由
把钥匙按字母顺序分类
现在,项目的顺序取决于浏览器的顺序
使用obj中的键的迭代对象返回
语法
看起来浏览器通常遵循提供键的策略
按照其定义的顺序,尽管存在例外
删除和恢复密钥时。看见
最好的方法是通过这样的过滤器将对象转换为数组
差不多
其他机制,然后按照需要的顺序手动排序
在
循环中。因此,当您执行内部ng repeat
时,您缺少订单。您可以按照您想要的顺序显式绑定值。在我看来,数据已经按照您期望的顺序显示了@KhalidHussain请运行代码片段它不起作用properly@Jimbrooism是的,在你的代码片段中它不起作用,@KhalidHussain我发现了问题,代码片段在angular 1.2.23上运行,plnkr在1.5.3中,如果你将1.5.3更改为1.2.23,它将不起作用