2016-05-28 3 views
0

私はAngularJsアプリケーションで作業しています。オブジェクトには、showOnHomeというオプションがあります。値がtrueに設定されている場合はプロダクトを表示し、falseに設定されている場合は非表示にします。 nodejsサーバでjsonデータに基づいてdivのコンテンツを表示する方法

app.get('/cameras/:id', function(req, res){ 
var cameraId = parseInt(req.params.id); 
var data = {}; 
for (var i=0, len=cameras.length; i<len; i++){ 
    if(cameras[i].id === cameraId){ 
     data = cameras[i]; 
     break; 
    } 
} 
res.json(data); 
}); 

app.get('/cameras', function(req, res){ 
res.json(cameras); 
}); 

var cameras = [ 
         { 
         "id": 1, 
         "title": "BVO473N 850TVL IR Dome Camera", 
         "features": [ 
          "2.0 Megapixel CMOS image sensor", 
          "2 megapixel high definition image quality", 
          "Minimum illumination of 0.1 Lux at F1.2 and 0 Lux with IR On", 
          "42 units of IR LEDs with an IR range of up to 30m", 
          "Supports dual streaming", 
          "Supports mobile surveillance via iOS, Android, Windows Mobile, BlackBerry", 
          "Supports plug and play - no port forwarding or networking knowledge required", 
          "Ingress Protection rating of IP66", 
          "Power Supply: DC 12V" 
         ], 
         "picture": "images/cam-look.png", 
         "showOnHome": true, 
         }, 
         ]; 


<div class="row" ng-repeat="cam in cameras"> 
      <hr ng-if="!$first" /> 
      <div ng-show="cam.showOnHome"> 
       <div class="col-sm-4 col-sm-push-8"> 
        <img ng-src="{{cam.picture}}" alt="Description"  class="img-responsive" /> 
       </div> 

       <div class="col-sm-8 col-sm-pull-4"> 
        <p class="lead">{{ cam.title }}</p> 
        <ul class="specs list-unstyled"> 
         <li ng-repeat="feature in cam.features">{{ feature  }}</li> 
        </ul> 
        <strong class="more"><a href="#/product/{{ cam.id  }}">Learn More</a></strong> 
       </div> 
      </div> 

      </div> 
+0

あなたの問題は何ですか? –

+0

showOnHomeの値に基づいてアイテムを表示/非表示にできない – user1250285

答えて

1

はあなたngShow/ngIfバブルまで試してみてください。

<div class="row" ng-if="cam.showOnHome" ng-repeat="cam in cameras"> 

あなたの中に置く場合は、外側のdivはまだレンダリング。

また、var cameras(デバッグ用?)を初期化します。
コントローラテンプレートでアクセスするには$scope.camerasにする必要があります。

+0

を試しましたが、これは動作しません。その工場ではまだ私は$スコープを使用する必要がありますか? – user1250285

+0

工場コードが表示されない場合、どうすればよろしいですか?とにかく、テンプレートは独自の '$ scope'変数を使います。それをアクセスに割り当てる必要があります。 '{{カメラ}}'をテンプレートに書き込んで、あなたが正しいことを確認してください。 –

関連する問題