[英]AppGyver Steroids Supersonic Views
我正在設法切換視圖/將視圖傳遞到另一個視圖。
我有一個正在使用和服API的應用程序,所有應用程序都具有超音速背景,並且看起來不錯。 我在API中有1個字符串和2個對象。 我有一個頁面正在使用名為event的頁面調用事件的完整列表:
{{event.eventdescription}}
The Event#Index controller is:
angular
.module('event')
.controller("IndexController", function ($scope, Event, supersonic) {
$scope.events = null;
$scope.showSpinner = true;
Event.all().whenChanged( function (events) {
$scope.$apply( function () {
$scope.events = events;
$scope.showSpinner = false;
});
});
});
And all of that displays properly. The issue is when I click on one of those items shown which should go to the specific event I get nothing. And I'm sure I'm doing this wrong or don't understand enough about switching views. I've read many examples, but I'm not getting how it all goes together.
這是我的活動#顯示頁面。 非常通用,只是在此時嘗試加載任何信息。
<div ng-controller="ShowController">
<super-navbar>
<super-navbar-title>
Show
</super-navbar-title>
</super-navbar>
<div class="padding">
{{ event.eventdescription }}
</div>
</div>
和showcontroller:
angular
.module('event')
.controller("ShowController", function ($scope, Event, supersonic) {
$scope.events = null;
Event.all().whenChanged( function (events) {
$scope.$apply( function () {
});
});
});
並且這總是返回空白頁。 當我檢查日志時,它顯示Undefined.undefined,我不確定這是什么意思。
非常感謝對此有任何見識。 在appgyver文檔中,我看到了一個叫做的東西。
var view = new supersonic.ui.View("bananas#show");
supersonic.ui.layers.push(view);
但是我不確定該如何使用? 任何見解都表示贊賞。
因此,我有更新:
這是我正在使用的event#index。
<div ng-controller="IndexController">
<super-navbar>
<super-navbar-title>
Event Index
</super-navbar-title>
</super-navbar>
<ul class="list" ng-hide="events.length == 0">
<super-navigate view-id="event#show" data-params-id="{{event.id}}" ng-repeat="event in events">
<li class="item item-icon-right">
<h2 ng-bind="event.EventTitles['text']"></h2>
<img ng-src="{{ event.HeadlineImages.src }}" width="100px" height="100px">
<p> {{ event.eventdescription }} </p>
<i class="icon super-ios7-arrow-right"></i>
</li>
</super-navigate>
</ul>
</div>
和索引控制器
angular
.module('event')
.controller("IndexController", function ($scope, Event, supersonic) {
$scope.events = null;
Event.all().whenChanged( function (events) {
$scope.$apply( function () {
$scope.events = events;
});
});
});
顯示html頁面。
<div ng-controller="ShowController">
<super-navbar>
<super-navbar-title>
Show
</super-navbar-title>
</super-navbar>
<div class="padding">
<p>
{{event.eventdescription}}
</p>
</div>
</div>
ShowController
angular
.module('event')
.controller("ShowController", function ($scope, Event, supersonic) {
supersonic.ui.views.current.params.onValue( function (Event) {
$scope.events = event.id;
});
Event.find($scope.events).then( function (Event) {
$scope.$apply( function () {
$scope.event = Event;
});
});
});
我也更新了structure.coffee
rootView:
location: "event#index"
preloads: [
{
id: "event#show"
}
{
id: "using-the-scanner"
location: "example#using-the-scanner"
}
]
任何幫助表示贊賞。
看起來好像不是在ShowController中設置了數據。 我之前對此發表過評論。 我認為您需要使用帶有location
屬性和data-params-id
<super-navigate>
傳遞事件data-params-id
或任何您想要的參數名稱。 然后在ShowController中,您可以使用以下命令進行訪問:
supersonic.ui.views.current.params.onValue( function (values) {
// values.nameOfPropertyPassedInCouldBeEventId
$scope.id = values.id;
});
然后,您可以執行以下操作以通過id訪問事件:
Event.find($scope.id).then( function (theEvent) {
$scope.$apply( function () {
$scope.event = theEvent;
});
});
現在,在您擁有{{ event.eventdescription }}
視圖中,應該有一些數據。
還有另一個關於視圖何時可見的含義,即每次您看到該視圖頁面時,都會觸發:
supersonic.ui.views.current.whenVisible( function () {
// your code for watching events
});
好吧,在嘗試了幾個星期之后,盡管如此,但我仍然無法使它開始運作。.我想我終於可以解決這個了……似乎最大的問題是使用和服和AppGyver。 JSON文件已在和服中使用以下方式更新:
function transform(data) {
data.results.collection1 = data.results.collection1.map(function(o) {
o.eventdescription = {
text: o.eventdescription
}
return o;
});
return data;
}
這將清除作為API向App Gyver導出/傳入的JSON文件,以便所有部分都是對象。 (我知道,也許沒什么大不了的,但是我只是想讓它盡可能干凈)。 為了讓您了解在“和服修改結果”框中->之前使用此腳本的前后:
"EventTitles": {
"href": "http://",
"src": "http://.jpg",
"text": "Lorem Ipsum"
},
"HeadlineImages": {
"href": "http://",
"src": "http://.jpg",
"text": "Lorem Ipsum"
},
"eventdescription":"Lorem Ipsum"
},
它將eventdescription保留為字符串而不是對象,然后保留AFTER:
"EventTitles": {
"href": "http://",
"src": "http://.jpg",
"text": "TEXT"
},
"HeadlineImages": {
"href": "http://",
"src": "http://.jpg",
"text": "TEXT"
},
"eventdescription": {
"text": "TEXT"
},
因此,將其運行到和服中后,您可以看到所有條目都是“對象”。 因此,您可以在鏈接中的apikey之后使用&kimmodify = 1:
https://www.kimonolabs.com/api/{indentifier}{apikey}&kimmodify=1
下一步,正如我在AppGyver社區向我解釋的那樣,對於要創建的JSON / API中的每個項目,幾乎都需要一個“ id”的種類,以便能夠使用ShowController在上創建合理/可行的url字符串。 show.html。
從索引轉到特定的條目視圖時,應該會創建類似/app/tier/showid=123456789
。
(您可以使用Mac上的IOS Emulator在Mac上通過Safari Web Inspector在AppGyver中使用調試模式來找到URL。或者在使用Android Emulator時使用http://localhost:[some port number]/location/of/app
的瀏覽器(推薦的Genymotion)。
因此,要做到這一點,在和服中,請在APIKEY之后但在進行諸如此類的修改之前,在您的網址末尾使用API哈希添加&kimhash = 1
https://www.kimonolabs.com/api/{indentifier}{apikey}&kimhash=1&kimmodify=1
。 請參閱: 和服API文檔-Re:Hash 。
這會產生類似
"EventTitles": {
"href": "http://",
"src": "http://.jpg",
"text": "TEXT"
},
"HeadlineImages": {
"href": "http://",
"src": "http://.jpg",
"text": "TEXT"
},
"eventdescription": {
"text": "TEXT"
},
"hash":"1a2b3c4d5e6f7g8h9z"},
為每個條目創建一個隨機的“標識符”。
現在,這就是我現在停留的地方。 ...因為需要輸入的API URL是:
https://www.kimonolabs.com/api/{indentifier}{apikey}&kimhash=1&kimmodify=1
並且當您在后端上配置API時,我看不到要輸入此新的&kimhash = 1&kimmodify = 1的區域,該區域必須位於URL的末尾才能調用格式正確且ID正確的API,如我所見,沒有這樣做的參考。
http://docs.appgyver.com/supersonic/guides/data/other-data-providers/kimono-labs/
我覺得這是弄清所有內容並最終使它開始工作的最后一步。 最后一個顯然是重新訪問將ID拖入ShowController的過程,我對是否可以弄清楚這最后一部分感到有些自信。
有任何想法嗎??
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.