关于ui / template模块我一直收到以下错误:
<?php
//This is a required file for Goutte framework
//This file is used for screen scrapping
//and web crowlling
require 'vendor/autoload.php';
use Goutte\Client;
//===============================================
//connection to database include file
include_once('Connections/elecom_connect.php');
mysqli_select_db($elecom_connect,$database_elecom_connect);
$sql = "SELECT * FROM link_data";
$query = mysqli_query($elecom_connect,$sql);
if (!$query){
echo 'Database error: ' .mysqli_error($elecom_connect);
}
//===============================================
//looping into the rows of url links stored
//in the database for fetching and scrapping
while ($row = mysqli_fetch_array($query)) {
$urls[] = $row;
}
//===============================================
function getFunctions($node) {
$client = new Client();
$guzzleclient = new \GuzzleHttp\Client([
'timeout' => 60,
'verify' => false,
]);
// Hackery to allow HTTPS
$client->setClient($guzzleclient);
$selctors = array();
$data = array();
//========================================
//Using Goutte framework to get the client url
$crawler = $client->request('GET',$node);
//========================================
//Filter the DOM by calling an anonymous
//function on each node (Find all URLs)
$crawler->filter('section.products a.link')->each(function ($url) {
//storing the scrapped data in an array
var_dump($selctors['url'] = $url->attr('href'));
});
//=======================================
//Filter the DOM by calling an anonymous
//function on each node (Find all Images)
$crawler->filter('.image-wrapper img')->each(function ($img) {
//storing the scrapped data in an array
var_dump($selctors['img'] = $img->attr('src'));
});
//======================================
//Filter the DOM by calling an anonymous
//function on each node (Find all Brands)
$crawler->filter('h2.title span.brand')->each(function ($brand) {
//storing the scrapped data in an array
var_dump($selctors['brand'] = $brand->text());
//Used for debugging
});
//======================================
//Filter the DOM by calling an anonymous
//function on each node (Find all Names)
$crawler->filter('h2.title span.name')->each(function ($name) {
//storing the scrapped data in an array
var_dump($selctors['name'] = $name->text());
});
//======================================
//Filter the DOM by calling an anonymous
//function on each node (Find all Prices)
$crawler->filter('span.price-box')->each(function ($price) {
//storing the scrapped data in an array
var_dump($selctors['price'] = $price->text());
});
$data[] = $selctors;
return $data;
}
//End of function
foreach ($urls as $url){
$lists[] = getFunctions($url['link']);
foreach ($lists as $list){
var_dump($m = $list['img']);
var_dump($b = $list['brand']);
var_dump($n = $list['name']);
var_dump($l = $list['url']);
var_dump($p = $list['price']);
$content = file_get_contents($m);
//Store in the filesystem.
$save_path = "cachedPages/$rid.$num.jpg";
file_put_contents($save_path,$content);
echo 'succes';
}
}
?>
由于某些原因,我无法在NativeScript中使用file:///app/tns_modules/tns-core-modules/ui/builder/builder.js:195:56: JS ERROR Error: Building UI from XML. @file:///app/main-page.xml:38:13
> Module 'ui/template' not found for element 'Template'.
> Could not find module 'ui/template'. Computed path
标记来获取以下代码:
<template>
我按以下方式构建数组:
<GridLayout>
<ListView items="{{ groceryList }}" itemTemplateProperty="list-group" itemTap="navigateToTasks" separatorColor="white">
<ListView.itemTemplate>
<template>
<Label text="{{ name }}" class="list-group-item-heading" />
</template>
<template>
<Label text="{{ grocery }}" class="list-group-item-heading" />
</template>
</ListView.itemTemplate>
</ListView>
</GridLayout>
由于某些原因,我也不能包含未找到的ui / template模块。我试着将以下内容放在main-page.js中:
var pageData = new observableModule.fromObject({
groceryList: new ObservableArray([
{ name: "Cool" },
{ name: "bread" },
{ name: "cereal"},
{ grocery: "id"}
])
});
但它显然不起作用。
答案 0 :(得分:1)
我花了一些时间来解决这个问题,但是一旦你引入了多个模板,你需要将ListView.itemTemplate更改为ListView.itemTemplate s (即最后的's' !)
<GridLayout>
<ListView items="{{ groceryList }}" itemTemplateProperty="list-group" itemTap="navigateToTasks" separatorColor="white">
<ListView.itemTemplates>
<template>
<Label text="{{ name }}" class="list-group-item-heading" />
</template>
<template>
<Label text="{{ grocery }}" class="list-group-item-heading" />
</template>
</ListView.itemTemplates>
</ListView>
</GridLayout>