yanzhuoni 2017-07-20 03:34
浏览 1800

knockout.js 关于用于嵌套的数组无关系的foreach多层嵌套报undefined的错误

问题描述:

我要实现ko的foreach多层嵌套,用于foreach的两个数组没有关系,第二层foreach绑定的数组报错:
Message: Unable to process binding "foreach: function (){return p2 }"
Message: p2 is not defined

代码:

js:
viewModel = {

p1 : ko.observableArray(
[
{ firstName: 'Bert', lastName: 'Bertington' },
{ firstName: 'Charles', lastName: 'Charlesforth' },
{ firstName: 'Denise', lastName: 'Dentiste' }
]
),
p2 : ko.observableArray(
[
{ firstName: 'Bert', lastName: 'Bertington' },
{ firstName: 'Charles', lastName: 'Charlesforth' },
{ firstName: 'Denise', lastName: 'Dentiste' }
]
),
}

html:

<div data-bind="foreach:p1">
    <div>我是p1</div>
    <div data-bind="foreach:p2">
        <li>我是p2</li>
    </div>
</div>
报错:

knockout-3.2.0.debug.js:2890 Uncaught ReferenceError: Unable to process binding "foreach: function (){return p1 }"
Message: Unable to process binding "foreach: function (){return p2 }"
Message: p2 is not defined
    at foreach (eval at createBindingsStringEvaluator (knockout-3.2.0.debug.js:2503), <anonymous>:3:60)
    at knockout-3.2.0.debug.js:3739
    at Object.init (knockout-3.2.0.debug.js:4859)
    at init (knockout-3.2.0.debug.js:3764)
    at knockout-3.2.0.debug.js:2867
    at Object.ignore (knockout-3.2.0.debug.js:1194)
    at knockout-3.2.0.debug.js:2866
    at Object.arrayForEach (knockout-3.2.0.debug.js:121)
    at applyBindingsToNodeInternal (knockout-3.2.0.debug.js:2852)
    at applyBindingsToNodeAndDescendantsInternal (knockout-3.2.0.debug.js:2732)

请各位大牛帮忙看看。
谢谢。



  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 oracle集群安装出bug
    • ¥15 关于#python#的问题:自动化测试
    • ¥15 教务系统账号被盗号如何追溯设备
    • ¥20 delta降尺度方法,未来数据怎么降尺度
    • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
    • ¥15 再不同版本的系统上,TCP传输速度不一致
    • ¥15 高德地图点聚合中Marker的位置无法实时更新
    • ¥15 DIFY API Endpoint 问题。
    • ¥20 sub地址DHCP问题
    • ¥15 delta降尺度计算的一些细节,有偿