javascript 使用 angularjs 创建对象列表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31159601/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 13:22:53 来源:igfitidea点击:
create list of object with angularjs
提问by user567
I have an array of strings, I use this code to add a new item
我有一个字符串数组,我使用此代码添加一个新项目
$scope.list.push(name);
But I don't want to add only the name, I want to do something like
但我不想只添加名称,我想做类似的事情
$scope.list.push(data); // data contain name and age
How can I create data object ?
如何创建数据对象?
采纳答案by binariedMe
just write
写就好了
var data = {name : "sampleName", age : 18};
$scope.list.push(data);