大佬教程收集整理的这篇文章主要介绍了使用AngularJS跟踪当前所选项目,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我无法想像的是如何同时进行:
>允许选择项目,触发更新标签和输入框文本以显示新选择的项目的名称
>允许在输入框中编辑名称,触发更新显示当前显示的项目名称的标签
>编辑名称应反映在原始模型项目中
目前,我正在尝试通过一个标志来跟踪哪个项目是最新的,而这并不是我想要的.理想情况下,我将使用isCurrent = true的项目直接引用项目来替换下面的currentItem.
`<div id="CurrentItem" data-ng-model="currentItem">{{CurrentItem.namE}}</div>`
当前项目名称输入框:
`<input id="Itemname" type="text" data-ng-model="currentItem" value="{{CurrentItem.namE}}" />`
显示所有项目:
<div data-ng-repeat="item in items" data-ng-click="changeItem(item)">` <img src="images/ItemIcon.png"> <div>{{item.namE}}</div>
控制器:
var CoreAppController = function($scope,$LOCATIOn) { $scope.changeItem = function(item) { var length = $scope.items.length; while(length-- ) { $scope.items[length].isCurrent = false; } $scope.currentItem = item; $scope.items.indexOf(item).isCurrent = false; } $scope.createItem = function(name,layout) { $scope.items.push({ id: $scope.items.length + 1,name: name,isCurrent: false }); } // Initialisation $scope.items = []; $scope.createItem("Item 1"); $scope.createItem("Item 2"); $scope.items[0].isCurrent = true; $scope.currentItem = $scope.items[0]; }
任何建议赞赏!
JS
app.controller('MainCtrl',function($scopE) { $scope.items = [ { name: 'foo' },{ name: 'bar' },{ name: 'test' } ]; $scope.ediTing = null; $scope.editItem = function(item) { $scope.ediTing = item; } });
和标记
<body ng-controller="MainCtrl"> <ul> <li ng-repeat="item in items"> {{item.namE}} <a ng-click="editItem(item);">edit</a> </li> </ul> <div ng-show="ediTing"> <input type="text" ng-model="ediTing.name"/> <span>{{ediTing.namE}}</span> </div> </body>
希望有帮助.如果您需要更多描述,请告知我们.
以上是大佬教程为你收集整理的使用AngularJS跟踪当前所选项目全部内容,希望文章能够帮你解决使用AngularJS跟踪当前所选项目所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。