Everyone monkey good, recently saw the table-driven method, just encounter a similar situation, so try to achieve. But I don't think it's happening at all. Please look at the code. A total of three questions
Is there a better way to define the table above? Although it is a manual list of all the possibilities, but it feels silly ... If there is more than one condition, or n conditions, then there is absolutely no way to manually enumerate ...
If there's an elegant little notation?
Why am I here return e[3]; Doesn't interrupt foreach.
Thank you for your reply.
function Getparentid (level, Focustype, AddType, select_id, parent_id) {//Focustype 0 = Node 1 = Event AddType 0 = Node 1 = matter var default_id = 1; var array = [//[level,focustype,addtype,returnkey] [1, 0, 0, select_id],//Select the first node, select node, add node-- > returns the key of the current node [1, 1, 0, default_id],//Select the first node, option, add node--return 1 [1, 0, 1, select_id],//Select First layer node, select node, add Item--return key of current node [1, 1, 1, parent_id],//Select first node, optional, plus--Return parent node key [0, 1, 0, parent_id],//non-first node, optional, add node--Return parent node key [0, 0, 0, select_id],//non-first layer node, select node, add node--return key of current node [0, 0, 1, select_id],//non-first node, select node, add matter--returns the key of the current node [0, 1, 1, parent_id]//non-first node, optional, plus Events--Return to parent node key]; /* * What better way to define a table above question 1? * Although there is an artificial list of all the possibilities, but it feels silly ... If there is more than one condition, or n conditions, then there is absolutely no way to manually enumerate ... * */var id = default_id; Array.foreach (function (e) {if (e[0] = = Level && ; E[1] = = Focustype && e[2] = = AddType/* Question 2 here if there is an elegant point of writing it? */) {id = e[3]; /* Question 3 Why am I here return e[3]; Does not interrupt foreach? */ } }); return ID; }
Reply content:
Everyone monkey good, recently saw the table-driven method, just encounter a similar situation, so try to achieve. But I don't think it's happening at all. Please look at the code. A total of three questions
Is there a better way to define the table above? Although it is a manual list of all the possibilities, but it feels silly ... If there is more than one condition, or n conditions, then there is absolutely no way to manually enumerate ...
If there's an elegant little notation?
Why am I here return e[3]; Doesn't interrupt foreach.
Thank you for your reply.
function Getparentid (level, Focustype, AddType, select_id, parent_id) {//Focustype 0 = Node 1 = Event AddType 0 = Node 1 = matter var default_id = 1; var array = [//[level,focustype,addtype,returnkey] [1, 0, 0, select_id],//Select the first node, select node, add node-- > returns the key of the current node [1, 1, 0, default_id],//Select the first node, option, add node--return 1 [1, 0, 1, select_id],//Select First layer node, select node, add Item--return key of current node [1, 1, 1, parent_id],//Select first node, optional, plus--Return parent node key [0, 1, 0, parent_id],//non-first node, optional, add node--Return parent node key [0, 0, 0, select_id],//non-first layer node, select node, add node--return key of current node [0, 0, 1, select_id],//non-first node, select node, add matter--returns the key of the current node [0, 1, 1, parent_id]//non-first node, optional, plus Events--Return to parent node key]; /* * What better way to define a table above question 1? * Although there is an artificial list of all the possibilities, but it feels silly ... If there is more than one condition, or n conditions, then there is absolutely no way to manually enumerate ... * */var id = default_id; Array.foreach (function (e) {if (e[0] = = Level && ; E[1] = = Focustype && e[2] = = AddType/* Question 2 here if there is an elegant point of writing it? */) {id = e[3]; /* Question 3 Why am I here return e[3]; Does not interrupt foreach? */ } }); return ID; }
Question 1, 2:
One of the items in the table is information that is used to match patterns. This information is simple can be [1, 0, 0]
represented by such a pure data (the following if the essence of a data into the behavior of the interpreter), complicated than the use of anonymous functions
Question 3. Anything you return will not let foreach break