第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

angular.js 數(shù)據(jù)僅顯示最近的參考

angular.js 數(shù)據(jù)僅顯示最近的參考

函數(shù)式編程 2022-05-26 11:21:28
我想要多個文本元素,通過函數(shù)動態(tài)添加,鍵控始終顯示輸入文本字段的內(nèi)容。相反,綁定的文本僅顯示在最近添加的文本元素上,而所有其他文本元素都會消失(?)。即使是我引用的正文中寫入的原始 span 標(biāo)簽也不再更新到用戶提供的數(shù)據(jù)(不是說您可以在下面的示例中說出最后一部分,因為它是隱藏的)。w3school 代碼在這里運(yùn)行:https ://www.w3schools.com/code/tryit.asp?filename=GD4AV18UABPF<!DOCTYPE html><html><script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>  <body>  <div ng-app=""> <script>    function linkPairing() {        var divElement = angular.element(document.querySelector('.transaction'));        var $hidden = angular.element(document.querySelector('.hiddenNodeName'));        divElement.append($hidden);        divElement.append("<br />");    }     </script>  <p>Input something in the input box:</p>  <form>  <p>Name: <input type="text" ng-model="newNodeName"></p>  <p>{{newNodeName}}</p>  <p>{{newNodeName}}</p>  <button class="addNewTransaction" id="addNewTransaction" type="button" onclick="linkPairing()">Go</button>                  </form>  <div hidden><span class="hiddenNodeName" >{{newNodeName}}</span></div>  <p class="transaction"></p>  </div></body></html>我意識到這種用于添加綁定數(shù)據(jù)引用的隱藏標(biāo)記方法可能是非常規(guī)的,并且根據(jù)其他問題,顯示的引用通??赡苡梢韵聝?nèi)容生成:var $div = $("<span>{{newNodeName}}</span>");divElement.append($compile($div)($scope));$scope.$apply();我嘗試了上面的變體,但甚至無法獲得示例中看到的部分成功。我懷疑我需要對角度有更深入的了解,尤其是范圍,才能通過這種方法取得成功。我同時使用 jquery 和 angular,并閱讀 stackOverflow 的意見以將 js 模塊負(fù)載降至最低。最初一切都在 jquery 中,但是當(dāng)我使用具有鏈接數(shù)據(jù)顯示的特殊功能時,Angular 中的 ng-bind 數(shù)據(jù)看起來非常吸引人。由于不確定我最終是否會成功,我現(xiàn)在不愿意將所有內(nèi)容重構(gòu)為 angular.js。這個變通辦法可以按我的預(yù)期運(yùn)行嗎?
查看完整描述

2 回答

?
RISEBY

TA貢獻(xiàn)1856條經(jīng)驗 獲得超5個贊

這是工作示例:https ://www.w3schools.com/code/tryit.asp?filename=GD4KGYTO3RCF


還有一個片段


<!DOCTYPE html>

<html>

   <!--module starts surrounds body tag name is myapp -->

  <body ng-app="myapp">

  <!--controller surrounds the  div tag ,A controller is associated with module for functionality purpose-->

  <div ng-controller="myctrl">

  <form >

  Input something in the input box <br><br>

  Name: <input type="text" ng-model="newNodeName">

  <!-- we use ng click  for click in angular js -->

  <button  id="btn-newTransation" type="button"                   

  ng-click="linkPairing()">Go</button>

  

  </form>

  <!-- ng-repeat repeats the html inside it , nodes is array, node is each iteration's value , track by $index to avoid duplication error and get index

  ng-repeat="node in nodes"

  -->

  <!--ng repeat usually expects array but to just repeat an element some time this will work as shortcut-->

  <div ng-repeat="x in [].constructor(count) track by $index" class="nodes">

   <p>{{newNodeName}}</p>

  </div>

  {{message}}

  <!-- i dont know why are you using following tags for -->

  <div hidden>

  <span class="hiddenNodeName">{{newNodeName}}</span></div>

  <p class="transaction"></p>

  </div>

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js">

</script>

<script>

    //initializing the myapp with controller

    angular.module("myapp",[]).controller("myctrl",function($scope){

    //variables in $scope are accessible in html example inside interpolation {{newNodeName}}

     $scope.message="";

    $scope.count=0;

  $scope.linkPairing=function(){ 

     $scope.count++;

     if($scope.count==3){

       $scope.message="Did it work? if it worked please upvote and mark it as correct "

   }

     }

    }); 

</script>

</body>

</html>


查看完整回答
反對 回復(fù) 2022-05-26
?
慕尼黑的夜晚無繁華

TA貢獻(xiàn)1864條經(jīng)驗 獲得超6個贊

這比我所擁有的更接近,并為我提供了一個陣列解決方案的良好開端(謝謝,Supercool)。不完全是我所追求的。這是我從您的代碼中得到的狀態(tài):


[State 1., after typing "1st" and pressing Go]

input box: 1st

1st


[State 2. after adding "2nd," and pressing Go]

input box: 1st 2nd

1st

1st 2nd


[End State. after adding "3rd," and pressing Go]

input box: 1st 2nd 3rd

1st

1st 2nd

1st 2nd 3rd

我想看到的是:


[State 1., after typing "1st" and pressing Go]

input box: 1st

1st


[State 2. after adding "2nd," and pressing Go]

input box: 1st 2nd

1st 2nd

1st 2nd


[End State. after adding "3rd," and pressing Go]

input box: 1st 2nd 3rd

1st 2nd 3rd

1st 2nd 3rd

1st 2nd 3rd

此外,在按下“Go”之間的每個按鍵狀態(tài)之后,所有生成的文本都將反映輸入框中的任何內(nèi)容。包括上述示例的所有這些中間狀態(tài),倒數(shù)第二個將是:


[Penultimate state. in the middle of typing out "3rd" and before pressing Go]

input box: 1st 2nd 3r

1st 2nd 3r

1st 2nd 3r

我認(rèn)為我可以獲得這種功能,因為我認(rèn)為(仍然這樣做?)角度的 {{reference}} 鏈接到原始的,并且無論你有多少,當(dāng)你制作它們等等,都會自動更新。 .


查看完整回答
反對 回復(fù) 2022-05-26
  • 2 回答
  • 0 關(guān)注
  • 113 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號