Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/442.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 带有惰性绑定的Pager.js_Javascript_Html_Knockout.js_Pager - Fatal编程技术网

Javascript 带有惰性绑定的Pager.js

Javascript 带有惰性绑定的Pager.js,javascript,html,knockout.js,pager,Javascript,Html,Knockout.js,Pager,我正在尝试使用Pager.js创建一个单页应用程序。我的结构如下: #word/definition #word/example #word/synonym 因此,定义,示例,等等都是带有页面绑定的div: <div data-bind="page: {id: 'word'}"> <div data-bind="page: {id: 'definition'}"> <-- stuff goes here --> <div data-bi

我正在尝试使用Pager.js创建一个单页应用程序。我的结构如下:

#word/definition
#word/example
#word/synonym
因此,
定义
示例
,等等都是带有
页面
绑定的div:

<div data-bind="page: {id: 'word'}">
  <div data-bind="page: {id: 'definition'}">
    <-- stuff goes here -->
  <div data-bind="page: {id: 'example'}">
    <-- stuff goes here -->
如何加载ViewModel,使三条路线“共享”它?我尝试将其加载为

<div data-bind="page: {id: 'word', withOnShow: getJsonWord}>
  <div data-bind="page: {id: 'definition'}">
    <-- stuff goes here -->
  <div data-bind="page: {id: 'example'}">
    <-- stuff goes here -->

我猜您当前的
getJsonWord
正在执行jquery异步ajax调用,这意味着最终的JSON不是直接从函数调用返回的

您需要包装对pager.js的ajax调用以注入回调

vm构造函数中的Javascript

your_root_vm.getJsonWord = function(callback) {
  $.getJSON(your_url, function(data) { callback(data); });
};
对于您提到的所有视图都可见的另一个问题,如果可能的话,请提供一个JSFIDLE

your_root_vm.getJsonWord = function(callback) {
  $.getJSON(your_url, function(data) { callback(data); });
};