申し訳ありませんが、私はこの1つにあまりにも多くの時間を渡している、完全に自明だが何とか私はできるそれを並べ替える。オブジェクトがFirebaseに存在しない場合、他のデータを表示する方法は?
私はDOMにオブジェクトからのデータを表示しようとしています:
// Listen to every people in our query...
geoQuery40.on("key_entered", function(key) {
// ... and look them up by key ...
restaurantsRef40.child(key).on("value", function(snapshot42) {
var restaurant40 = snapshot42.val();
console.log(restaurant40);
var displayBusinessName = snapshot42.val().name;
console.log(displayBusinessName);
var displayBusinessDescription = snapshot42.val().description;
$timeout(function() {
if (snapshot42.exists()) {
$timeout(function() {
$scope.displayBusinessName = displayBusinessName;
$scope.displayBusinessDescription = displayBusinessDescription;
})
} else {
$timeout(function() {
$scope.displayBusinessName = "displayBusinessName";
$scope.displayBusinessDescription = "displayBusinessDescription";
})
}
})
});
});
は今、snapshot42が空の場合は/何もしています、私は私が示すものを再定義します。それだけでは機能しません。ここで
は私のDOMです:
<div class="content2" ng-controller="businessPageController">
<div id="map"></div>
<div class="profile-info">
<!-- *profile-image/image profile -->
<img class="profile-image" src="img/100.jpg">
<!-- *profile-name/name profile -->
<h3 class="profile-name">{{displayBusinessName}}</h3>
<!-- *profile-description/description profile -->
<span class="profile-description">
{{displayBusinessDescription}}
</span>
<br /><br />
</div>
</div>
任意のソリューション?
ジャストヘッドアップ。 '.on( 'value'、[callback])を使うときは、実際に値変更イベントのリスナーを登録しています。したがって、key_enteredイベントが2回目で発生しなくても、コールバックが実行される可能性があります。 "key_entered"イベントがトリガされたときに値を一度だけ取得したい場合は、once( 'value'、[callback]) 'を使うか、より良いですが' once( 'value')を使用します。 )。 –