2017-03-28 1 views
0

Here, I am trying to update input type a attribute text only, if the obj.idPartnerOffice == json.idPartnerOffice condition is true. How can I update project name only ?1つのテキストのみを設定する方法<a attribute list?

if (json.idPartnerProject == "0") { 
 
       json.idPartnerProject = Math.random(); 
 
       hidJson.Form5.Projects.push(json); 
 
       $("#divbindProjectlist").append('<a href="#" id="anchorproject1" class="list-group-item projectList" >' + json.ProjectName + '<input type="hidden" name="hiddenproject1" class="hidprojectId" value="' + json.idPartnerProject + '" /></a>'); 
 
      } 
 
      else { 
 
       $.each(hidJson.Form5.Projects, function (i, obj) { 
 
        if (obj.idPartnerProject == json.idPartnerProject) { 
 
         hidJson.Form5.Projects[i] = json; 
 
         $("#anchorproject1").html(json.ProjectName).append('<input type="hidden" name="hiddenproject1" class="hidprojectId" value="' + json.idPartnerProject + '" />'); 
 
        } 
 
       }); 
 

 

 
      }

Here is image for html view with list of projects, enter image description here

今、すべての非表示フィールドの値が変更されます。どうすれば修正できますか?

+0

問題は何ですか? – Satpal

+0

最初の AbhiJA

+0

obj変数またはjson変数を変更したいですか? – Keith

答えて

0

あなたの最善の策は、アンカーにid属性を追加し、(彼らはとにかく、クリック可能な要素ではないです)アンカータグの外で(名前はところで属性欠けている)隠しフィールドを移動するために、おそらくです:

<a href="#" id="anchorproject1" class="list-group-item projectList">asdfasd</a> 
<input type="hidden" name="hiddenproject1" class="hidprojectId" value="12345" /> 
その後、

とテキストにアクセスするために、いくつかのjQueryを使用します。

$("#anchorproject1").html("aaaaaa"); 

編集:

アンカータグのテキストを変更する方法を尋ねたところで、隠されたフィールドについて質問しています。あなたの心を作りなさい - あなたは実際に何が助けを必要としますか?

+0

私はhiddenfieldの名前を追加しました。しかし、今ではすべてのhiddendfieldの値が変更され、2番目の AbhiJA

+0

@AbhiJA 'json.idPartnerProject = Math.random();'を使用し、 'value =" '+ json.idPartnerProject +' "'を入れているので、隠しフィールドの値が変更されました。これを実行するたびに、 'Math.random()'は新しい値を生成します - それはあなたが望むものではありませんか? – sleeyuen

+0

'if(json.idPartnerProject ==" 0 ")'ここでは新しい 'idPartnerProject'だけが発生しています。しかし、既存のIDを含む 'else'のケースでは。だから私は 'if(obj.idPartnerProject == json.idPartnerProject)'プロジェクト名を AbhiJA

関連する問題