• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<template>
2  <list>
3    <cell repeat="{{items}}">
4      <example-list-item title="{{title}}" url="{{url}}"></example-list-item>
5    </cell>
6  </list>
7</template>
8
9<script>
10  require('weex-components');
11  module.exports = {
12    data: {
13      root: '', // examples, examples/syntax, test ...
14      items: [
15        {name: 'hello', title: 'Hello World', url: ''}
16      ]
17    },
18    created: function() {
19      var bundleUrl = this.$getConfig().bundleUrl;
20      console.log('hit', bundleUrl);
21      var dirs = this.root.split('/');
22      dirs.forEach(function(dir, index) {
23        if (!dir) dirs.splice(index, 1);
24      });
25      var root = dirs.length > 0 ? dirs[0] : '';
26      var subRoot = dirs.length > 1 ? dirs.slice(1).join('/') + '/' : '';
27
28      var nativeBase;
29      var isAndroidAssets = bundleUrl.indexOf('your_current_IP') >= 0 || bundleUrl.indexOf('file://assets/')>=0;
30      var isiOSAssets = bundleUrl.indexOf('file:///') >= 0 && bundleUrl.indexOf('WeexDemo.app') > 0;
31      if (isAndroidAssets) {
32        nativeBase = 'file://assets/';
33      }
34      else if (isiOSAssets) {
35        // file:///var/mobile/Containers/Bundle/Application/{id}/WeexDemo.app/
36        // file:///Users/{user}/Library/Developer/CoreSimulator/Devices/{id}/data/Containers/Bundle/Application/{id}/WeexDemo.app/
37        nativeBase = bundleUrl.substring(0, bundleUrl.lastIndexOf('/') + 1);
38      }
39      else {
40        var host = 'localhost:12580';
41        var matches = /\/\/([^\/]+?)\//.exec(this.$getConfig().bundleUrl);
42        if (matches && matches.length >= 2) {
43          host = matches[1];
44        }
45        nativeBase = '//' + host + '/' + root + '/build/' + subRoot;
46      }
47      var h5Base = './index.html?page=./' + root + '/build/' + subRoot;
48      // in Native
49      var base = nativeBase;
50      if (typeof window === 'object') {
51        // in Browser or WebView
52        base = h5Base;
53      }
54
55      for (var i in this.items) {
56        var item = this.items[i];
57        if (!item.url) {
58          item.url = base + item.name + '.js';
59        }
60      }
61      // see log in Android Logcat
62      if (this.items.length) console.log('hit', this.items[0].url);
63    }
64  }
65</script>
66
67<style>
68</style>