Knockout.js knockoutJS中的匿名模板

Knockout.js knockoutJS中的匿名模板,knockout.js,Knockout.js,我在knockout.js中有一段代码,如下所示: <div> ... some other markup here <div class="topicDetail" data-bind='template: { name: "topicTemplate", data: activeTopic}'> </div> </div> <script type="text/html" id="topicTemplate">

我在knockout.js中有一段代码,如下所示:

<div>
    ... some other markup here

    <div class="topicDetail" data-bind='template: { name: "topicTemplate", data: activeTopic}'> </div>

</div>

<script type="text/html" id="topicTemplate">
    <ul class="querylist" data-bind='template: {name: "queryTemplate", foreach: queries}'></ul> 
</script>                                           

<script type="text/html" id ="queryTemplate">
    <li class="query" data-bind="css: { active: selected()}, queryType: type">
        <span class="querylink" data-bind="click: select">{{= text}}</span>
        <span data-bind="withdocs: positiveExamples"></span>
        <span data-bind='person: searcher'>&nbsp;</span>
        <span data-bind='time: time'></span>
    </li>
</script>
<div class="topicDetail" data-bind="with: activeTopic">
    <ul class="querylist" data-bind="foreach: queries">
         <li class="query">
            <span class="querylink" data-bind="click: select">{{= text}}</span>
            <span data-bind="withdocs: positiveExamples"></span>
            <span data-bind='person: searcher'>&nbsp;</span>
            <span data-bind='time: time'></span>
         </li>
    </ul>
</div>
但这失败了,错误如下:

Uncaught Error: Unable to parse binding attribute.
Message: ReferenceError: queries is not defined;
Attribute value: foreach: queries
在敲除-1.2.1.debug.js的第1226行中。这是指
UL
数据绑定


我创建了一个抽象化了这个问题的模型,但是小提琴可以工作。我还应该看什么来追踪这一点呢?

如果您使用的是如您所述的淘汰1.2.1:

…在敲除-1.2.1.debug.js的第1226行中。这是指UL数据 绑定

。。。那这就是你的问题。您需要使用1.3.0版。有关详细信息,请参阅中的“控制流绑定”部分


你的提琴之所以能工作,是因为它使用了最新版本的敲除功能。

听起来你至少有一个案例,在
activeTopic
中有一些东西,但没有
查询
数组。
activeTopic
是如何初始化的?它会不会没有“查询”数组?是的,匿名模板在KO1.3中工作。您正在使用1.2。