学习python让我忘记了所有的角色,这就是我的故事,我坚持不懈。它甚至让我忘记了我的谷歌技能,因为我无法在任何地方找到类似的问题。最接近的可能是How to append to a json object in angular js,除此之外也无效。在数组中添加ng-model值作为分组的孩子
我有10组两个输入字段,标题和说明。我想将它们作为子元素添加到数组中,所以我最终将在我的json中拥有十个属性,并且每个属性又具有两个子元素属性。我尝试过推,concat,即使是老式的+ =在绝望中,但没有任何工作。我必须完全错过这个明显的。
以下是各行的样子,虽然数量变化(从1到10):
<label class="sr-only" for="shorttitle1">short title</label>
<input type="text" class="form-control" ng-click="addIdea()" ng-model="idea1.title" placeholder="title">
<label class="sr-only" for="description1">description</label>
<input type="text" class="form-control" ng-click="addIdea()" ng-model="idea1.description" placeholder="description">
在我的控制器,下面是我根据上面的链接试图版本,这是不工作比任何CONCAT或推好做:
$scope.ideas = [
{idea : $scope.idea1.title, $scope.idea1.description},
{idea : $scope.idea2.title, $scope.idea2.description},
{idea : $scope.idea3.title, $scope.idea3.description}
];
我不断收到了意想不到的点标记的错误(如,在$范围-点idea1点)。当我把简单的文本作为一个测试时,我得到了一个意外的右括号的令牌错误。
我甚至试着做一个watchCollection,只是为了看看控制器是否会注意,但我什么都没有。我试着只看着idea1,然后是$ scope.idea1,然后是$ scope.idea1.title,watchCollection就在那里。
这就是我想要的它看起来就像你,大致有:
$scope.ideas = [
{
type : 'title goes here',
description : 'description goes here'
},{
type : 'title goes here',
description : 'description goes here'
},{
type : 'title goes here',
description : 'description goes here'
}
];
我已检查真的很明显 - NG-应用程序不在同一水平NG-控制器,I打电话给正确的管制员,我没有任何古怪的拼写错误。
帮助?
好吧,那清除了一个问题,让我发现*真实*问题。谢谢! – kl02