我有一个递归函数,如下所示.
public function findnodeintree($cats,$cat_id)
{
foreach($cats as $node)
{
if((int)$node['id'] == $cat_id)
{
echo "finded";
$finded = $node;
break;
}
else
{
if(is_array($node) && array_key_exists('children', $node)){
$this->findnodeintree($node['children'],$cat_id);
}
}
}
return $finded;
}
Run Code Online (Sandbox Code Playgroud)
例如
$node =$this->findnodeintree($category_Array, 169);
Run Code Online (Sandbox Code Playgroud)
它让我高兴
"founded"
Run Code Online (Sandbox Code Playgroud)
遇到PHP错误
Severity: Notice
Message: Undefined variable: finded
Run Code Online (Sandbox Code Playgroud)
数组结构就像
[0] => Array
(
[id] => 0
[name] => MAIN CATEGORY
[depth] => 0
[lft] => 1
[rgt] => 296
[children] => Array
(
[0] => Array
(
[id] => 167
[name] => …
Run Code Online (Sandbox Code Playgroud) 我正在使用Citrix负载均衡器.
在此背后,有4个虚拟Nginx服务器.ip类似于172.16.10.40,172.16.10.41,172.16.10.42,172.16.10.43
和1个测试服务器172.16.10.50.
Nodejs安装在位于172.16.10.50的测试服务器上.
我已经为像sub.example.com这样的nodejs创建了一个子域.
我的nodejs应用程序正在使用8070端口.
我想使用Websocket而不是xhr-pooling.通过下面的代码和配置,我在Chrome控制台中看到了这一点
Status Code:101 Switching Protocols
Run Code Online (Sandbox Code Playgroud)
但框架上没有任何东西出现.不推.
如果我将socketURL更改为
var socketURL = http://172.16.10.50:8070
Run Code Online (Sandbox Code Playgroud)
Websocket在测试平台上没有任何问题(172.16.10.50).
但是,在真正的平台中我必须使用' http://sub.example.com:8070 ';
如果我设置socket.io:'transports',['xhr-polling']; xhr-polling正在发挥作用.但我想使用WebSocket.
nginx version: nginx/1.4.1
node v0.8.8
socket.io v0.9.16
Run Code Online (Sandbox Code Playgroud)
我该做什么?
谢谢.
app.js
var app =
server = require('http').createServer(app)
, io = require('socket.io').listen(server,{ log: false })
, url = require('url')
, http= require('http')
,redis = require("redis");
//io.set('transports', ['xhr-polling']);
var livefeed = redis.createClient();
server.listen(8070);
livefeed.on("message", function(channel, message){
console.log("%s, the message : %s", channel, message);
io.sockets.in(channel).emit(channel,message);
});
io.sockets.on('connection', function (socket) {
console.log("["+socket.id+"] …
Run Code Online (Sandbox Code Playgroud) HTML
<table cellpadding="0" cellspacing="0" border="0">
<thead>
<tr><th width="483"><span>Product Name</span></th></tr>
</thead>
<tbody data-bind='foreach: basket.model.products()'>
<tr><td><div class="ml10 productDetails" data-bind="text: name"></div></td></tr>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
JAVASCRIPT代码
var ProductLine = function(data) {
var self = this;
self.name = ko.observable(data.name);
};
function BasketModel(data) {
var self = this;
self.initialData = ko.observable(data);
self.products = ko.observableArray();
$.each(self.initialData().products,function(i,val){
self.products.push(new ProductLine(this));
});
}
function renderBasket(data){
basket = { model: new BasketModel(data)};
ko.applyBindings(basket.model);
}
$(document).ready(function(){
var sampleData = [{"name":"product 1"},{"name":"product 2"}];
renderBasket(sampleData );
});
Run Code Online (Sandbox Code Playgroud)
当我在ajax帖子中添加一个新产品到篮子时,我用响应数据调用下面的函数
renderBasket(response.data);
Run Code Online (Sandbox Code Playgroud)
实施例response.data喜欢[{ "名称": "产品1"},{ "名称": "产品2"},{ "名称": …