Javascript 从MySql将polymer paper listbox绑定到php数组
我是polymer的新手,我正在尝试为我的公司创建一个简单的管理web应用程序。 因此,我有一个来自数据库的查询,返回一个简单的varchar列表(客户姓名列表),我想在纸质listbox元素或iron list元素中显示该列表(这些项目可以单击并显示有关此人的信息) 我曾尝试在items属性中使用直接php,但不起作用:Javascript 从MySql将polymer paper listbox绑定到php数组,javascript,php,html,mysql,polymer,Javascript,Php,Html,Mysql,Polymer,我是polymer的新手,我正在尝试为我的公司创建一个简单的管理web应用程序。 因此,我有一个来自数据库的查询,返回一个简单的varchar列表(客户姓名列表),我想在纸质listbox元素或iron list元素中显示该列表(这些项目可以单击并显示有关此人的信息) 我曾尝试在items属性中使用直接php,但不起作用: <iron-list items="<?php echo $jsonresult;?>" as="item"> 标题 .横截面{ 填充:0!重要
<iron-list items="<?php echo $jsonresult;?>" as="item">
标题
.横截面{
填充:0!重要;
}
.阿凡达{
显示:内联块;
宽度:40px;
高度:40px;
边界半径:50%;
溢出:隐藏;
背景:#ccc;
}
纸品{
--文件项目:{
光标:指针;
}
}
.子列表{
左侧填充:20px;
右边填充:20px;
}
客户表
聚合物({
是:“主视图”
});
var arraySource=;
document.getElementById('list')。items=arraySource;
提前感谢您的帮助,抱歉语法-->英语不是我的第一语言。您需要将主视图组件提取到单独的文件中,然后导入它:
<link rel="import" href="./main-view.html">
<body unresolved>
<template is="dom-bind">
<main-view></main-view>
</template>
</body>
否则它不会运行。
此外,通过在Polymer对象中定义变量,尝试使用Polymer的数据绑定:
Polymer ({
is: 'main-view',
properties: {
arraySource: {
type: Array,
value: function() {
return <?php echo json_encode($rows); ?>;
}
}
}
});
聚合物({
是‘主视图’,
特性:{
arraySource:{
类型:数组,
值:函数(){
返回;
}
}
}
});
您需要将主视图组件提取到单独的文件中,然后将其导入:
<link rel="import" href="./main-view.html">
<body unresolved>
<template is="dom-bind">
<main-view></main-view>
</template>
</body>
否则它不会运行。
此外,通过在Polymer对象中定义变量,尝试使用Polymer的数据绑定:
Polymer ({
is: 'main-view',
properties: {
arraySource: {
type: Array,
value: function() {
return <?php echo json_encode($rows); ?>;
}
}
}
});
聚合物({
是‘主视图’,
特性:{
arraySource:{
类型:数组,
值:函数(){
返回;
}
}
}
});
好的,根据这里的一些建议,我将这个东西分成两个脚本,结果如下: 它正在工作 list-view.html
<head>
<meta charset="utf-8">
<script src="../bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
<!-- import the components to build up the list -->
<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="../bower_components/paper-listbox/paper-listbox.html">
<link rel="import" href="../bower_components/paper-item/paper-item.html">
</head>
<body>
<dom-module id="list-view">
<template>
<div class="horizontal-section-container">
<div>
<h4 style="margin-left: 15px; ">Customer Table</h4>
<div class="horizontal-section">
<paper-listbox id="list">
<template is="dom-repeat" items="[[arraySource]]">
<paper-item on-tap="_itemTapped">[[item.user]]</paper-item>
</template>
</paper-listbox>
</div>
</div>
</div>
</template>
<script>
Polymer ({
is: 'list-view',
properties: {
arraySource: Array
},
_itemTapped: function (e)
{
var item = e.model.item;
console.log(item);
}
});
</script>
</dom-module>
</body>
<html>
<head>
<meta charset="utf-8">
<title>SITE</title>
<script src="../bower_components/webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="./list-view.html">
</head>
<body>
<dom-module id="main-view">
<template>
<div>
<list-view id="list" array-source="<?php echo $jsonSource ?>" as="item"></list-view>
</div>
</template>
<script>
Polymer({
is: 'main-view'
});
</script>
</dom-module>
</body>
</html>
客户表
[[item.user]]
聚合物({
是:‘列表视图’,
特性:{
arraySource:数组
},
_项目:功能(e)
{
var项目=e.model.item;
控制台日志(项目);
}
});
main-view.html
<head>
<meta charset="utf-8">
<script src="../bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
<!-- import the components to build up the list -->
<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="../bower_components/paper-listbox/paper-listbox.html">
<link rel="import" href="../bower_components/paper-item/paper-item.html">
</head>
<body>
<dom-module id="list-view">
<template>
<div class="horizontal-section-container">
<div>
<h4 style="margin-left: 15px; ">Customer Table</h4>
<div class="horizontal-section">
<paper-listbox id="list">
<template is="dom-repeat" items="[[arraySource]]">
<paper-item on-tap="_itemTapped">[[item.user]]</paper-item>
</template>
</paper-listbox>
</div>
</div>
</div>
</template>
<script>
Polymer ({
is: 'list-view',
properties: {
arraySource: Array
},
_itemTapped: function (e)
{
var item = e.model.item;
console.log(item);
}
});
</script>
</dom-module>
</body>
<html>
<head>
<meta charset="utf-8">
<title>SITE</title>
<script src="../bower_components/webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="./list-view.html">
</head>
<body>
<dom-module id="main-view">
<template>
<div>
<list-view id="list" array-source="<?php echo $jsonSource ?>" as="item"></list-view>
</div>
</template>
<script>
Polymer({
is: 'main-view'
});
</script>
</dom-module>
</body>
</html>
场地
好的,根据这里的一些建议,我已经将它拆分为两个脚本,结果如下:
它正在工作
list-view.html
<head>
<meta charset="utf-8">
<script src="../bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
<!-- import the components to build up the list -->
<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="../bower_components/paper-listbox/paper-listbox.html">
<link rel="import" href="../bower_components/paper-item/paper-item.html">
</head>
<body>
<dom-module id="list-view">
<template>
<div class="horizontal-section-container">
<div>
<h4 style="margin-left: 15px; ">Customer Table</h4>
<div class="horizontal-section">
<paper-listbox id="list">
<template is="dom-repeat" items="[[arraySource]]">
<paper-item on-tap="_itemTapped">[[item.user]]</paper-item>
</template>
</paper-listbox>
</div>
</div>
</div>
</template>
<script>
Polymer ({
is: 'list-view',
properties: {
arraySource: Array
},
_itemTapped: function (e)
{
var item = e.model.item;
console.log(item);
}
});
</script>
</dom-module>
</body>
<html>
<head>
<meta charset="utf-8">
<title>SITE</title>
<script src="../bower_components/webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="./list-view.html">
</head>
<body>
<dom-module id="main-view">
<template>
<div>
<list-view id="list" array-source="<?php echo $jsonSource ?>" as="item"></list-view>
</div>
</template>
<script>
Polymer({
is: 'main-view'
});
</script>
</dom-module>
</body>
</html>
客户表
[[item.user]]
聚合物({
是:‘列表视图’,
特性:{
arraySource:数组
},
_项目:功能(e)
{
var项目=e.model.item;
控制台日志(项目);
}
});
main-view.html
<head>
<meta charset="utf-8">
<script src="../bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
<!-- import the components to build up the list -->
<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="../bower_components/paper-listbox/paper-listbox.html">
<link rel="import" href="../bower_components/paper-item/paper-item.html">
</head>
<body>
<dom-module id="list-view">
<template>
<div class="horizontal-section-container">
<div>
<h4 style="margin-left: 15px; ">Customer Table</h4>
<div class="horizontal-section">
<paper-listbox id="list">
<template is="dom-repeat" items="[[arraySource]]">
<paper-item on-tap="_itemTapped">[[item.user]]</paper-item>
</template>
</paper-listbox>
</div>
</div>
</div>
</template>
<script>
Polymer ({
is: 'list-view',
properties: {
arraySource: Array
},
_itemTapped: function (e)
{
var item = e.model.item;
console.log(item);
}
});
</script>
</dom-module>
</body>
<html>
<head>
<meta charset="utf-8">
<title>SITE</title>
<script src="../bower_components/webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="./list-view.html">
</head>
<body>
<dom-module id="main-view">
<template>
<div>
<list-view id="list" array-source="<?php echo $jsonSource ?>" as="item"></list-view>
</div>
</template>
<script>
Polymer({
is: 'main-view'
});
</script>
</dom-module>
</body>
</html>
场地
检查ChromeDevTools是否有任何错误消息?检查ChromeDevTools是否有任何错误消息?