加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – Angular js双向数据绑定问题,用于管理“文本框”到

发布时间:2020-12-17 17:30:58 所属栏目:安全 来源:网络整理
导读:我正在使用具有“编辑”字段的数据模型.并基于“编辑”值我使用文本框或标签.我希望一旦用户在编辑后点击“确定”然后文本框应该更改为标签.但不知怎的,它不起作用.以下是jsfiddle示例.请帮忙. http://jsfiddle.net/dilipkumar2k6/zEdY8/2/`”u0026gt;JSFi
我正在使用具有“编辑”字段的数据模型.并基于“编辑”值我使用文本框或标签.我希望一旦用户在编辑后点击“确定”然后文本框应该更改为标签.但不知怎的,它不起作用.以下是jsfiddle示例.请帮忙.

http://jsfiddle.net/dilipkumar2k6/zEdY8/2/`”u0026gt;JSFiddleLink

解决方法

我已经修改了你的 Fiddle,你必须把它改成这样的东西

<div ng-app="" ng-controller="controller" id="contentsDivID">
<div ng-repeat="chapter in chapters">
<ng:switch on="chapter.edit">
            <div ng:switch-when="true">
                <input type="text" ng-model="chapter.title" ng-model="chapter.title" />                
                <a ng-click="addChapter($index);"><i class="icon-ok"></i></a>
            </div>          
            <div ng:switch-when="undefined">
                    <label>{{chapter.title}}</label>
            </div>
            </ng:switch>        
    </div>       
</div>

然后你的JavaScript代码到此

function controller($scope)
{
    $scope.chapters=[
            {
                "_id": "567456746","title": "Growth and Development","type": "section","edit":true
            },{
                "_id": "34563465345","title": "Links between Areas of Development","type": "section"
            },{
                "_id": "8776545645","title": "Characteristics of Development","thumbnail": "/xopus/images/templates/media-1-top-right.png","type": "section"
            }
        ];

    $scope.addChapter = function(index) {
        $scope.chapters[index].edit = undefined;
    }
}

你可能想要结账angular concepts documentation – 它应该给你一些关于角轨道如何改变模型的重点.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读