Select a tree node does not work - javascript

I have an application in Extjs and I need to select a specific node to expand the tree.
I am using the following method:
var record = tree.getRootNode().FindChild('text', 'employee', true);
tree.getSelectionModel().select(record);
in this way does not work, but if I select any one node and then run the above method, it works without problems.
Help please
UPDATE
CODE:
tree.expandPath(route, "text", "->", function() {
var record = tree.getRootNode().findChild('text','BASE',true);
tree.getSelectionModel().select(record);
});

It is possible that the node is not loaded yet. If you need to expand the tree, the best way is to use expandPath method and if you need to select the node then do it in expandPath callback.

When do you try to select the node with this code? While the tree panel got generated? In this case, perhaps some code from treepanels implementation will reset the selection. So for testing try it with a lock on the the selectionModel:
var record = tree.getRootNode().findChild('text','BASE',true);
tree.getSelectionModel().select(record);
tree.getSelectionModel().setLocked(true);
(If you know already the node which should be expanded while loading data for the store, you can also set "expanded" to true in the data for this specific record/node. Then the expansion is done by ExtJS automatically.)

Friends thanks for your help, I was able to solve my problem.
Apparently I did not select the node because it had not shown the window and the nodes were not available, so here add a listener after render.
so I stay my code:
listeners: {
afterrender : function(){
this.selectPath(this.ruta, 'text', '->', function (s,n) {
var nodeEl = Ext.get(this.view.getNode(n));
nodeEl.scrollIntoView(this.view.el, false, true);
});
}
}
this solution apart from selecting me too the node moves to its location in the tree.
hopefully serve them.
Greetings!

Related

How to get parent table of selection in word using office.js 1.1?

Is anyone aware of a way to get access to the parent table of a selection in a version of Word that only has access to the 1.1 js api? We've been developing with 1.3 in mind, but must now also support the earlier version, rendering the following code broken:
async checkForInsideTable(ctx: Word.RequestContext, sel: Word.Range) {
let pt = sel.parentTable;
ctx.load(pt);
try {
await ctx.sync();
this.tableObject = pt;
return true;
} catch {
this.tableObject = null;
return false;
}
}
Over the past week we've tried a lot of different approaches, such as using bindings, wrapping table in content controls, or even relying on the styling tags. But nothing gets us to a position where we can get access to the parent or detect if the selection is within a specific element, and upgrading the version of Word is not an option.
I am afraid there is no direct way as 1.1 doesn't have table object/class.
You can first call getSelectedDataAsync(type: ooxml), then in the ooxml, you can analyze whether there is table out of the selection. But as mentioned above, you still can't get the table.

About mxGraph: how can I first add Edge, and add my own custom attribute, then add to the graph?

Because I register a listener about the CELL_ADD to justify when I add two different types of edges, I deal with them in different ways.
But the problem is I failed to add the edge after I change my method to "add edge" action"
HERE IS MY FIRST successful version :
graph.insertEdge(parent, null, '', defiVertex, outVertex);
HERE IS MY WANTED NEW VERSION but failed:
edge.edge = true;
edge.type = AUTO_INSERT_EDGE;
graph.addEdge(edge);
THANK FOR HELP!!
Not sure what you are trying to do, but why don't you override the addListener function? In there, you can retrieve the changes, and if the name is mxTerminalChange you know you are adding/modifying an edge:
model.addListener(mx.mxEvent.CHANGE, function(sender, evt) {
var changes = evt.getProperty('edit').changes;
if (changes[i].constructor.name == "mxTerminalChange") {
// Manage the add of a new connection
...
}
});
I change another way to finish my problem which is use the vue data attribute to help me record the state of the two add edge situations: when the edge is add by code, this.isAutoAdd = true, when user create the edge, this.isAutoAdd=false,so when in the listener, I just need to determine whether "isAutoAdd" is false to call the change function.

Querying the DOM in Windows 8 Apps from within a method

I'm struggling with this even after reading the MSDN documentation and the following online guides:
Codefoster
Stephen Walter
I think my problem is easy to fix and that I just am thinking about something in the wrong way. Basically I am querying my web service and on success running the following method. I am then trying to bind the result to my listview. For now I am using a hardcoded value publicMembers.itemlistwhich has been declared at the top of the document just to make sure I can actually bind to the list before doing it with my query results. Ignore line 2 for now.
Success Method:
_lookUpSuccess: function xhrSucceed(Result) {
var response = JSON.parse(Result.responseText);
listView = document.querySelector("#termTest");
ui.setOptions(listView, {
itemDataSource: publicMembers.itemList,
itemTemplate: document.querySelector(".itemtemplate"),
})
},
Now, instead of using document.querySelector, I have also tried with WinJS.Utilities.id and WinJS.Utilities.query, neither of which worked either. This doesn't break my code and introduce an error but it doesn't bind to the listview either so I think I have an issue in querying the right DOM element. However exactly the same code does work if I add it to the top of the script, it is only when I place it in this method that it stops working.
EDIT: Also to clarify, when I debug publicMembers.itemList is storing the values I expect them to be.
Please point out if I have explained things poorly and I will try and improve my question.
Thanks.
I haven't used WinJS.UI.setOptions, but rather this other way of setting the data source. Can you see if it works?
_lookUpSuccess: function xhrSucceed(result) {
var response = JSON.parse(result.responseText);
listView = document.querySelector("#termTest");
listView.winControl.itemDataSource = publicMembers.itemList;
},
This would assume you're defining the itemTemplate as part of the data-win-options attribute of your ListView's HTML element. You could also probably just do listView.winControl.itemTemplate = document.querySelector(".itemtemplate") if you prefer to set it programmatically.

Meteor template applying jQuery plugin after rendered

I am displaying a collection of "messages" in my Meteor app. When my template "messages" is rendered, I apply this jQuery plugin called "gridalicious", which basically displays the messages in a pinterest-like format.
All works well, but when I insert a new message, that new message is displayed twice. When I refresh the browser, the duplicate is gone.
I'm applying the plugin as follow
Template.messages.rendered = ->
$("#message_box").gridalicious
width:250
animate:false
selector:".message"
gutter:0
Basically, if I get rid of this plugin, things messages display correctly, without any duplicates.
I'm not sure what would be causing this problem.
yes, i have similar prob like this. for this plugin or same satuation, to avoid it duplicates your template instance you can try make a global variable to handle your message box status, add some condition to decide if this new message's id is already been inside your global status handler and already been rendered, then don't render it twice.
global scope
isAlreadyBeenReneredId = null
Template instance of messages
Template.messages.rendered = ->
if isAlreadyBeenReneredId isnt #data._id
isAlreadyBeenReneredId = #data._id
options =
width: 250
gutter: 0
$("#message_box").gridalicious options
not real code, but some idea you might want to try.
As far as I know, Meteor does not render everything again and again, but only the differences. So I think the problem is, that you call the jQuery plugin multiple times on the same element.
I don't know the plugin, but there seems to be an append method, maybe this could be useful?
Try this:
if (Meteor.isClient) {
Meteor.startup(function () {
$(document).ready(function (){
$("#message_box").gridalicious({
width:250,
animate:false,
selector:".message",
gutter:0
});
});
});
}
Sorry I didn't know how to write the equivalent in coffescript.

jstree node not getting created

I have created a very simple jstree.
On click of a link I am calling createNode() function. It does uses create function from the api to create a node.
It seems to be a common jquery problem that I am facing. Please let me know what is getting wrong.
Fiddle here - http://jsfiddle.net/juyMR/16/
Changing the line to:
$("#jsTreeDiv").jstree("create_node",$('#linodeid1'),false,"new name",false,false);
This will add to the root:
function createNode() {
$("#jsTreeDiv").jstree("create_node",$('#jsTreeDiv'),false,{ state: "leaf", data: "No rename!" },false,true);
}
You have to identify the parent of the node you want to add the new node too.

Categories

Resources