似乎没有创建淘汰观察者?

时间:2017-12-16 16:45:32

标签: javascript knockout.js

我正在开展一个项目,我刚从头开始,对于出了什么问题有一个清醒的头脑。现在我正在做这件事,我意识到我的淘汰赛观察者并没有真正起作用,我也不知道这是什么问题。

这是我的app.js

var places = [
{
    title: 'Cafe Mondegar',
    location: {
        lat: 18.9241,
        lng: 72.8321
    }
},
{
    title: 'Four Seasons Hotel Mumbai',
    location: {
        lat: 18.9971,
        lng: 72.8184
    },
},
{
    title: 'Gokul',
    location: {
        lat: 18.923100,
        lng: 72.832244
    }
},
{
    title: 'Grand Hyatt Mumbai',
    location: {
        lat: 19.0774,
        lng: 72.8513
    }
},
{
    title: 'Irani café',
    location: {
        lat: 19.063644,
        lng: 72.862288
    }
},
{
    title: 'Kohinoor Square',
    location: {
        lat: 19.0249,
        lng: 72.8415
    }
},
{
    title: 'Leopold Cafe',
    location: {
        lat: 18.9227,
        lng: 72.8317
    }
},
{
    title: 'Oberoi Trident',
    location: {
        lat: 18.927,
        lng: 72.8204
    }
},
{
    title: 'Punjabi Chandu Halwai Karachiwala',
    location: {
        lat: 19.042690,
        lng: 72.863337
    }
},
{
    title: 'The Table',
    location: {
        lat: 18.924121,
        lng: 72.833116
    }
},
{
    title: 'The Taj Mahal Palace Hotel',
    location: {
        lat: 18.9217,
        lng: 72.8330
    }
},
{
    title: 'Watson\'s Hotel',
    location: {
        lat: 18.9283,
        lng: 72.8311
    }
}
];

var viewModel = {

places: ko.observableArray(places),
num: ko.observable(34),
name: ko.observable('pankti')

};
console.log(viewModel.places[0]);
console.log(viewModel.num);
console.log(viewModel.name);

ko.applyBindings(viewModel);

这是我的HTML

<body>
   <ul class="title" data-bind="foreach: places">
       <li data-bind="text: title"></li>
   </ul>
   <div class="location"></div>

   <script type="text/javascript" src="js/libs/knockout-3.4.2.js"></script>
   <script src="js/app.js"></script>
</body>

console.log(viewModel.places[0])返回undefined

console.log(viewModel.num) returns 
ƒ c(){if(0<arguments.length)return c.Ua(c[F],arguments[0])&&(c.ia(),c[F]=arguments[0],c.ha()),this;a.l.sc(c);return c[F]}

我哪里错了?

0 个答案:

没有答案