Answered by:
Question about search contract

Question
-
Hi.
I'm developing a Windows 8 App, and I have a question.
I develop a App with Split App style (VS2012), and I just put a data to sampleGroups and sampleItems.
I added a Search Contract and change something like below.
_itemInvoked: function (args) {
args.detail.itemPromise.done(function itemInvoked(item) {
// TODO: Navigate to the item that was invoked.
nav.navigate("/pages/split/split.html", { item: Data.getItemReference(item.data) });
});
},I think this is right, but result isn't. I can search in Search Charm correctly, and result shows up correctly. But after I click the item I want, App just navigate me to first group page. It is almost same as samples in MSDN, but I think, something wrong in
nav.navigate("/pages/split/split.html", { item: Data.getItemReference(item.data) });
here. I debugged it, and it set and get right data, just navigate to same first split. Any solution?
Thx.
Tuesday, May 21, 2013 8:58 AM
Answers
-
Ok Got it , you have not touched the split.js. Then in search result JS your iteminvoked method should be :
_itemInvoked: function (args) { args.detail.itemPromise.done(function itemInvoked(item) { var groupKey = item.group.key; nav.navigate("/pages/split/split.html", { groupKey: groupKey }); }); },
- Girija
- Marked as answer by Yanping WangModerator Tuesday, May 28, 2013 6:59 AM
Wednesday, May 22, 2013 3:38 AM -
Using the group key you need to retrieve the data.. I am not sure if you changed that... See these lines of code :
this._group = (options && options.groupKey) ? Data.resolveGroupReference(options.groupKey) : Data.groups.getAt(0); // Get the group from group key this._items = Data.getItemsFromGroup(this._group); // Get items for the group
Have you removed some code from split.js?
I would suggest putting a breakpoint and debugging the split.js and see what is that you are missing.
- Girija
- Marked as answer by Yanping WangModerator Tuesday, May 28, 2013 6:59 AM
Thursday, May 23, 2013 11:24 PM
All replies
-
I donot think the issue is here.
Look at the "("/pages/split/split.js" .. something might be wrong there.
Can you post your code for split.js ?
- Girija
Tuesday, May 21, 2013 9:16 PM -
(function () {
"use strict";var appViewState = Windows.UI.ViewManagement.ApplicationViewState;
var binding = WinJS.Binding;
var nav = WinJS.Navigation;
var ui = WinJS.UI;
var utils = WinJS.Utilities;ui.Pages.define("/pages/split/split.html", {
/// <field type="WinJS.Binding.List" />
_items: null,
_group: null,
_itemSelectionIndex: -1,// This function is called whenever a user navigates to this page. It
// populates the page elements with the app's data.
ready: function (element, options) {
var listView = element.querySelector(".itemlist").winControl;// Store information about the group and selection that this page will
// display.
this._group = (options && options.groupKey) ? Data.resolveGroupReference(options.groupKey) : Data.groups.getAt(0);
this._items = Data.getItemsFromGroup(this._group);
this._itemSelectionIndex = (options && "selectedIndex" in options) ? options.selectedIndex : -1;element.querySelector("header[role=banner] .pagetitle").textContent = this._group.title;
// Set up the ListView.
listView.itemDataSource = this._items.dataSource;
listView.itemTemplate = element.querySelector(".itemtemplate");
listView.onselectionchanged = this._selectionChanged.bind(this);
listView.layout = new ui.ListLayout();this._updateVisibility();
if (this._isSingleColumn()) {
if (this._itemSelectionIndex >= 0) {
// For single-column detail view, load the article.
binding.processAll(element.querySelector(".articlesection"), this._items.getAt(this._itemSelectionIndex));
}
} else {
if (nav.canGoBack && nav.history.backStack[nav.history.backStack.length - 1].location === "/pages/split/split.html") {
// Clean up the backstack to handle a user snapping, navigating
// away, unsnapping, and then returning to this page.
nav.history.backStack.pop();
}
// If this page has a selectionIndex, make that selection
// appear in the ListView.
listView.selection.set(Math.max(this._itemSelectionIndex, 0));
}
},unload: function () {
this._items.dispose();
},// This function updates the page layout in response to viewState changes.
updateLayout: function (element, viewState, lastViewState) {
/// <param name="element" domElement="true" />var listView = element.querySelector(".itemlist").winControl;
var firstVisible = listView.indexOfFirstVisible;
this._updateVisibility();var handler = function (e) {
listView.removeEventListener("contentanimating", handler, false);
e.preventDefault();
}if (this._isSingleColumn()) {
listView.selection.clear();
if (this._itemSelectionIndex >= 0) {
// If the app has snapped into a single-column detail view,
// add the single-column list view to the backstack.
nav.history.current.state = {
groupKey: this._group.key,
selectedIndex: this._itemSelectionIndex
};
nav.history.backStack.push({
location: "/pages/split/split.html",
state: { groupKey: this._group.key }
});
element.querySelector(".articlesection").focus();
} else {
listView.addEventListener("contentanimating", handler, false);
if (firstVisible >= 0 && listView.itemDataSource.list.length > 0) {
listView.indexOfFirstVisible = firstVisible;
}
listView.forceLayout();
}
} else {
// If the app has unsnapped into the two-column view, remove any
// splitPage instances that got added to the backstack.
if (nav.canGoBack && nav.history.backStack[nav.history.backStack.length - 1].location === "/pages/split/split.html") {
nav.history.backStack.pop();
}
if (viewState !== lastViewState) {
listView.addEventListener("contentanimating", handler, false);
if (firstVisible >= 0 && listView.itemDataSource.list.length > 0) {
listView.indexOfFirstVisible = firstVisible;
}
listView.forceLayout();
}listView.selection.set(this._itemSelectionIndex >= 0 ? this._itemSelectionIndex : Math.max(firstVisible, 0));
}
},// This function checks if the list and details columns should be displayed
// on separate pages instead of side-by-side.
_isSingleColumn: function () {
var viewState = Windows.UI.ViewManagement.ApplicationView.value;
return (viewState === appViewState.snapped || viewState === appViewState.fullScreenPortrait);
},_selectionChanged: function (args) {
var listView = document.body.querySelector(".itemlist").winControl;
var details;
// By default, the selection is restriced to a single item.
listView.selection.getItems().done(function updateDetails(items) {
if (items.length > 0) {
this._itemSelectionIndex = items[0].index;
if (this._isSingleColumn()) {
// If snapped or portrait, navigate to a new page containing the
// selected item's details.
nav.navigate("/pages/split/split.html", { groupKey: this._group.key, selectedIndex: this._itemSelectionIndex });
} else {
// If fullscreen or filled, update the details column with new data.
details = document.querySelector(".articlesection");
binding.processAll(details, items[0].data);
details.scrollTop = 0;
}
}
}.bind(this));
},// This function toggles visibility of the two columns based on the current
// view state and item selection.
_updateVisibility: function () {
var oldPrimary = document.querySelector(".primarycolumn");
if (oldPrimary) {
utils.removeClass(oldPrimary, "primarycolumn");
}
if (this._isSingleColumn()) {
if (this._itemSelectionIndex >= 0) {
utils.addClass(document.querySelector(".articlesection"), "primarycolumn");
document.querySelector(".articlesection").focus();
} else {
utils.addClass(document.querySelector(".itemlistsection"), "primarycolumn");
document.querySelector(".itemlist").focus();
}
} else {
document.querySelector(".itemlist").focus();
}
}
});
})();Here it its! This code is never touched.
Wednesday, May 22, 2013 1:07 AM -
Ok Got it , you have not touched the split.js. Then in search result JS your iteminvoked method should be :
_itemInvoked: function (args) { args.detail.itemPromise.done(function itemInvoked(item) { var groupKey = item.group.key; nav.navigate("/pages/split/split.html", { groupKey: groupKey }); }); },
- Girija
- Marked as answer by Yanping WangModerator Tuesday, May 28, 2013 6:59 AM
Wednesday, May 22, 2013 3:38 AM -
very helpful!
Thank you, Hyo Bin.
Wednesday, May 22, 2013 4:57 AM -
Sorry, but 1 more thing.
_itemInvoked: function (args) { args.detail.itemPromise.done(function itemInvoked(item) { // TODO: Navigate to the item that was invoked. var groupKey = item.data.group.key; nav.navigate("/pages/split/split.html", { groupKey: groupKey }); }); },
I changed code like this, and it navigate to exact "group" but not content what I want. So I think I needs to change code like follow.
var itemContent = item.data.content;
nav.navigate("/pages/split/split.tml", { groupKey: groupKey, itemContent: itemContent });
but it still just navigate to group page 1st content. What should I do?
Wednesday, May 22, 2013 5:21 AM -
Using the group key you need to retrieve the data.. I am not sure if you changed that... See these lines of code :
this._group = (options && options.groupKey) ? Data.resolveGroupReference(options.groupKey) : Data.groups.getAt(0); // Get the group from group key this._items = Data.getItemsFromGroup(this._group); // Get items for the group
Have you removed some code from split.js?
I would suggest putting a breakpoint and debugging the split.js and see what is that you are missing.
- Girija
- Marked as answer by Yanping WangModerator Tuesday, May 28, 2013 6:59 AM
Thursday, May 23, 2013 11:24 PM