Javascript 在AngularJS中具有可配置选项的JSON数据

Javascript 在AngularJS中具有可配置选项的JSON数据,javascript,regex,json,angularjs,database-design,Javascript,Regex,Json,Angularjs,Database Design,项目可于 我正在开发一款Angular应用程序。它的目的是作为一种问卷形式。问题将按顺序显示。问题2问什么将取决于用户在问题1中做出的选择。 我设置了3个简单的json文件 { "questions" : [ {"id" : 1, "child" : 2, "step" : 1, "question" : "My name is [user]", "inputType" : "text"}, {"id" : 2, "child" : 4, "st

项目可于

我正在开发一款Angular应用程序。它的目的是作为一种问卷形式。问题将按顺序显示。问题2问什么将取决于用户在问题1中做出的选择。 我设置了3个简单的json文件

{
    "questions" : 
    [
        {"id" : 1, "child" : 2, "step" : 1, "question" : "My name is [user]", "inputType" : "text"},
        {"id" : 2, "child" : 4, "step" : 1, "question" : "I live by myself [none]", "inputType" : "none"},
        {"id" : 3, "child" : 5, "step" : 1, "question" : "I live with [animals]", "inputType" : "option"},
        {"id" : 4, "child" : 7, "step" : 2, "question" : "I would like to adopt [animals]", "inputType" : "option"},
        {"id" : 5, "child" : 6, "step" : 2, "question" : "My [animals] is [animals_year] old", "inputType" : "option"},
        {"id" : 6, "child" : 0, "step" : 3, "question" : "My [animals] is [sizes]", "inputType" : "option"},
        {"id" : 7, "child" : 0, "step" : 3, "question" : "I like [sizes] [animals]", "inputType" : "option"}
    ]
}

{
    "animals" : 
    [
        {"id" : 1, "option" : "cat"},
        {"id" : 2, "option" : "dog"},
        {"id" : 3, "option" : "panda"}
    ]
}
{
"sizes" : 
[
    {"id" : 1, "option" : "small"},
    {"id" : 2, "option" : "medium"},
    {"id" : 3, "option" : "large"}
]}
*这是3个独立的JSON文件(questions.JSON、anives.JSON和size.JSON)

我将解释如何在Angular中设置逻辑: 假设我们正在处理:
我与[animals]生活在一起| type:option.
我们使用JS RegEx获得:

a = 'I live with'; //pure text

b = 'animals'; //whatever between brackets will be used for the next http.get

And we pre write the HTML element of type:option
c = '<select>**TO DO**</selection>'
简而言之:我将questions.json中的内容分解为纯文本和选择选项的键。这些键用于查询选项表。选项(json格式)将被推入数组并显示在视图中

到目前为止,我已经能够正则表达式,过滤和提取数据到最小的单位。我有这样的东西:

$scope.filtered.pureText //an array contains the pure text
$scope.filtered.inBrackets //an array contains the key option between []
$scope.optionData //an array contains the option data after the json call
我的问题是: 这是为其他表的子查询设置数据(questions.json)的最佳方法吗? 如何使用动物和大小表中的数据构建
。并将这些选择框相应地放入问题中。例如:

I live with [animals]
becomes
<div>I live with
    <select>
        <option>Cat</option>
        <option>Dog</option>
        <option>Penguin</option>
    </select>
</div>
我和[动物]住在一起
变成
我和你住在一起
猫
狗
企鹅

很好的解释。但是如果您可以添加一个fiddle,那就更好了谢谢您,我已经添加了到目前为止我一直在JSFIDLE上工作的代码
I live with [animals]
becomes
<div>I live with
    <select>
        <option>Cat</option>
        <option>Dog</option>
        <option>Penguin</option>
    </select>
</div>