2017-01-03 9 views
0

Я работаю над приложением skype bot. У меня проблема с чтением узла из древовидной модели. Пример дерева-модели следует за дочерним узлом, но мой узел имеет вкладку diff для чтения системой.treemodel + skype-bots Невозможно прочитать свойство 'model' of undefined

XML ПРИМЕР-

<?xml version="1.0" encoding="UTF-8" ?> 
<rootmenu id="1" title="menu" description="What scenario would you like to run?"> 
    <MenuOption id="1.1" title="Company Data" response="You entered company data" description="What action would you like to perform"> 
     <HierarchyMenuItem id="1.1.1.1" title="Select new data " response="You entered select new filter"> 
      <action>Filter</action> 
     </HierarchyMenuItem> 
     <HierarchyMenuItem id="1.1.1.2" title="Navigate node" response="You entered select node"> 
      <action description="Current Filter is ">Hierarchy</action> 
      <HierarchyLevel level="1" name="One" navigateHierarchy="true"> 
       <action>RootAction</action> 
       <Option title="Select a Country"> 
        <OptionChoices id="1" title="One1" refNode="ForOne1" /> 
        <OptionChoices id="2" title="One2" refNode="ForOne2" /> 
        <OptionChoices id="3" title="One3" refNode="ForOne3" /> 
        <OptionChoices id="4" title="One4" refNode="ForOne4" /> 
       </Option> 
      </HierarchyLevel> 
    </HierarchyMenuItem> 
    </MenuOption> 
    <MenuOption id="1.2" title="Adhoc Data"> 
     <Option> 
      <OptionChoices id="1" title="Ad1" refNode="ForAdOne1" /> 
      <OptionChoices id="2" title="Ad2" refNode="ForAdOne2" /> 
      <OptionChoices id="3" title="Ad3" refNode="ForAdOne3" /> 
      <OptionChoices id="4" title="Ad4" refNode="ForAdOne4" /> 
     </Option> 
    </MenuOption> 
    <MenuOption id="1.3" title="(quit)"> 
    </MenuOption> 
</rootmenu> 

Читайте XML от Сервер-

function getXMLData(callback) { 
    var request = require('request'); 
    var DOMParser = require('xmldom').DOMParser; 
    var simpleconvertxml = require('simpleconvert-xml'); 
    request('http://demo.in/RefactoredXML.xml', function (error, response, body) { 
     if (!error && response.statusCode == 200) { 
      var xmlnode = new DOMParser().parseFromString([body].join('\n'), 'text/xml'); 
      var myNumber = simpleconvertxml.getXMLAsObj(xmlnode); 
      treeRoot = tree.parse(myNumber.rootmenu); 
      callback(treeRoot); 
     } 
    }) 
} 

Мой первый бот вызова

диалог вызова
bot.dialog('/menu', [ 
    function (session, args) { 
     getXMLData(function (treeRoot) { 
      //session.send('node place:'+treeRoot.model.title); 
      var firstChild = []; 
      for (var i = 0; i < treeRoot.model.MenuOption.length; i++) { 
       if(treeRoot.model.MenuOption[i].title !='' && treeRoot.model.MenuOption[i].title != undefined && treeRoot.model.MenuOption[i].title != null) { 
        firstChild.push(treeRoot.model.MenuOption[i].title); 
       } 
      } 
      if(firstChild.length > 0) { 
       builder.Prompts.choice(session, treeRoot.model.description,firstChild); 
// it shows builder.Prompts.choice(session, "What scenario would you like to run? ", "company data|adhoc data|(quit)"); 
      } else { 
       session.send('Something went wrong. You can use the back or top command.'); 
      } 
     }); 
    }, 
    function (session, results) { 
     if (results.response && results.response.entity != '(quit)') { 
      session.userData.profile.treeSelectdNodeTitle = results.response.entity; 
      getXMLData(function (treeRoot) { 
       for (var i = 0; i < treeRoot.model.MenuOption.length; i++) { 
        if(treeRoot.model.MenuOption[i].title == session.userData.profile.treeSelectdNodeTitle) { 
         session.userData.profile.treeSelectdNodeId  = treeRoot.model.MenuOption[i].id; 
         session.userData.profile.treeSelectdResponse = treeRoot.model.MenuOption[i].response; 
        } 
       } 
       session.send('resp ' + session.userData.profile.treeSelectdResponse); 
     if(treeRoot.hasChildren()) { 
       session.send('in the children'); 
       session.beginDialog('/get Tree Node'); 
      } else { 
       session.send('in the title'); 
       session.beginDialog('/'+ treeRoot.model.title); 
      } 
      }); 

     } else { 
      // Exit the menu 
      session.endDialog(); 
     } 
    }, 
    function (session, results) { 
     // The menu runs a loop until the user chooses to (quit). 
     session.replaceDialog('/menu'); 
    } 
]).reloadAction('reloadMenu', null, {matches: /^menu|show menu|top|top menu/i}); 

Меню должно отображать 1.company данных 2. AdHoc data 3. (quit), но показывается только 1.company данные 2.adhoc data и Issue в меню, если пользователь выбирает 1 вариант в качестве Compan y Данные не будут отправляться в состояние treeRoot.hasChildren().

bot.dialog('/get Tree Node', [ 
    function(session,agrs) { 
     getTreeNode(session); 
    } 
]); 


function getTreeNode(session) { 
    session.send("in tree "+ session.userData.profile.treeSelectdNodeId); 
    getXMLData(function(treeRoot) { 
     var nextLevel = treeRoot.first(function (node) { 
      return node.model.id === session.userData.profile.treeSelectdNodeId; 
     }); 
     session.send('selected title '+ nextLevel.model.HierarchyMenuItem[0].title); 
     /* var secondListChild = []; 
     for(var i = 0; i < nextLevel.model.HierarchyMenuItem.length; i++) { 
      if(nextLevel.model.HierarchyMenuItem[i].title !='' && nextLevel.model.HierarchyMenuItem[i].title != undefined && nextLevel.model.HierarchyMenuItem[i].title != null) { 
       secondListChild.push(nextLevel.model.HierarchyMenuItem[i].title); 
      } 
     } 
     if(secondListChild.length > 0) { 
      builder.Prompts.choice(session, nextLevel.model.description,secondListChild); 
     } else { 
      session.send('Something went wrong. You can use the back or top command.'); 
     } */ 
    }); 
} 

проблема с getTreeNode является session.send ('выбранный заголовок' + nextLevel.model.HierarchyMenuItem [0] .title); ^ TypeError: Не удается прочитать свойство 'модель' неопределенному

ответ

0

Got Solution ....

меня изменить XML разбора НПМ и его работа для меня ..

var parse  = require('xml-parser'); 
var inspect  = require('util').inspect; 
function getXMLData(callback) { 
    var request = require('request'); 
    request('http://ztdemo.headfitted.in/RefactoredXML.xml', function (error, response, body) { 
     if (!error && response.statusCode == 200) { 
      var obj = parse(body); 
      //console.log(inspect(obj, { colors: true, depth: Infinity })); 
      //callback(treeRoot); 

      treeRoot = tree.parse(obj.root); 
      callback(treeRoot); 
     } 
    }) 
} 

 Смежные вопросы

  • Нет связанных вопросов^_^