2016-06-30 15 views
-4

こんにちは誰がここに入力ボックスに値をプッシュすることができますか?一意性を保ち、リスト全体を出力してください。配列値を入力ボックスにプッシュするにはどうすればよいですか?

Names:<input id='names'/> 

var data = [{"name":"Lenovo Thinkpad 41A4298","website":"google"}, 
{"name":"Lenovo Thinkpad 41A2222","website":"google"}, 
{"name":"Lenovo Thinkpad 41Awww33","website":"yahoo"}, 
{"name":"Lenovo Thinkpad 41A424448","website":"google"}, 
{"name":"Lenovo Thinkpad 41A429rr8","website":"ebay"}, 
{"name":"Lenovo Thinkpad 41A429ff8","website":"ebay"}, 
{"name":"Lenovo Thinkpad 41A429ss8","website":"rediff"}, 
{"name":"Lenovo Thinkpad 41A429sg8","website":"yahoo"}]; 

var uniqueNames = []; 
for(i = 0; i< data.length; i++){  
    if(uniqueNames.indexOf(data[i].website) === -1){ 
     uniqueNames.push(data[i].website);   
    }   
} 

for(i = 0; i< uniqueNames.length; i++){  
    alert(uniqueNames[i]);  
} 

誰もオンラインで行っていないので手伝ってください!

+1

あなたは何を試してみましたか?誰かが評判のためにあなたのコードを入力するかもしれないのは間違いありませんが、あなたは何も学ばないでしょう。私たちにあなたの試行を見せてください、あなたがそこから解決するのを手伝ってくれます。 JavaScriptの基本を知っている方が簡単です。 – Script47

+1

**入力ボックスに値を入力してください**意味はなんですか? – brk

+0

@ user2181397テキストボックスや入力にテキストを追加したいと思っています。 – Script47

答えて

0

これはテキストボックスに追加されていないので、部分的な回答ですが、私はリストに追加することができました。ここのHTMLとJSとJSONは部分的(MVC5)ですが、長期的にはそうではない。しかし、私は半分の答えを持っていることを嬉しく思っています。開発者として、私たちは常に発達していくにつれて、より多くのことを学びます!そして、これが誰か;-)回答を助けることを願っています:

HTML: 
Names:<p id="uniqueWebsites"></p> 

JS: 
var uniqueNamesRes = ""; 

var data = [{"name":"Lenovo Thinkpad 41A4298","website":"google"}, 
{"name":"Lenovo Thinkpad 41A2222","website":"google"}, 
{"name":"Lenovo Thinkpad 41Awww33","website":"yahoo"}, 
{"name":"Lenovo Thinkpad 41A424448","website":"google"}, 
{"name":"Lenovo Thinkpad 41A429rr8","website":"ebay"}, 
{"name":"Lenovo Thinkpad 41A429ff8","website":"ebay"}, 
{"name":"Lenovo Thinkpad 41A429ss8","website":"rediff"}, 
{"name":"Lenovo Thinkpad 41A429sg8","website":"yahoo"}]; 

var uniqueNames = []; 
for(i = 0; i< data.length; i++){  
    if(uniqueNames.indexOf(data[i].website) === -1){ 
     uniqueNames.push(data[i].website);   
    }   
} 

for(i = 0; i< uniqueNames.length; i++){  
    uniqueNamesRes += uniqueNames[i] + "<br>"; 
} 

document.getElementById("uniqueWebsites").innerHTML = uniqueNamesRes; 
関連する問題